github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/add_comment_to_task.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package tasks 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the generate command 7 8 import ( 9 "context" 10 "net/http" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/circl-dev/runtime/middleware" 16 "github.com/circl-dev/validate" 17 ) 18 19 // AddCommentToTaskHandlerFunc turns a function with the right signature into a add comment to task handler 20 type AddCommentToTaskHandlerFunc func(AddCommentToTaskParams, interface{}) middleware.Responder 21 22 // Handle executing the request and returning a response 23 func (fn AddCommentToTaskHandlerFunc) Handle(params AddCommentToTaskParams, principal interface{}) middleware.Responder { 24 return fn(params, principal) 25 } 26 27 // AddCommentToTaskHandler interface for that can handle valid add comment to task params 28 type AddCommentToTaskHandler interface { 29 Handle(AddCommentToTaskParams, interface{}) middleware.Responder 30 } 31 32 // NewAddCommentToTask creates a new http.Handler for the add comment to task operation 33 func NewAddCommentToTask(ctx *middleware.Context, handler AddCommentToTaskHandler) *AddCommentToTask { 34 return &AddCommentToTask{Context: ctx, Handler: handler} 35 } 36 37 /* AddCommentToTask swagger:route POST /tasks/{id}/comments tasks addCommentToTask 38 39 Adds a comment to a task 40 41 The comment can contain ___github markdown___ syntax. 42 Fenced codeblocks etc are supported through pygments. 43 44 45 */ 46 type AddCommentToTask struct { 47 Context *middleware.Context 48 Handler AddCommentToTaskHandler 49 } 50 51 func (o *AddCommentToTask) ServeHTTP(rw http.ResponseWriter, r *http.Request) { 52 route, rCtx, _ := o.Context.RouteInfo(r) 53 if rCtx != nil { 54 *r = *rCtx 55 } 56 var Params = NewAddCommentToTaskParams() 57 uprinc, aCtx, err := o.Context.Authorize(r, route) 58 if err != nil { 59 o.Context.Respond(rw, r, route.Produces, route, err) 60 return 61 } 62 if aCtx != nil { 63 *r = *aCtx 64 } 65 var principal interface{} 66 if uprinc != nil { 67 principal = uprinc.(interface{}) // this is really a interface{}, I promise 68 } 69 70 if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params 71 o.Context.Respond(rw, r, route.Produces, route, err) 72 return 73 } 74 75 res := o.Handler.Handle(Params, principal) // actually handle the request 76 o.Context.Respond(rw, r, route.Produces, route, res) 77 78 } 79 80 // AddCommentToTaskBody A comment to create 81 // 82 // These values can have github flavored markdown. 83 // 84 // 85 // swagger:model AddCommentToTaskBody 86 type AddCommentToTaskBody struct { 87 88 // content 89 // Required: true 90 Content *string `json:"content"` 91 92 // user Id 93 // Required: true 94 UserID *int64 `json:"userId"` 95 } 96 97 // Validate validates this add comment to task body 98 func (o *AddCommentToTaskBody) Validate(formats strfmt.Registry) error { 99 var res []error 100 101 if err := o.validateContent(formats); err != nil { 102 res = append(res, err) 103 } 104 105 if err := o.validateUserID(formats); err != nil { 106 res = append(res, err) 107 } 108 109 if len(res) > 0 { 110 return errors.CompositeValidationError(res...) 111 } 112 return nil 113 } 114 115 func (o *AddCommentToTaskBody) validateContent(formats strfmt.Registry) error { 116 117 if err := validate.Required("body"+"."+"content", "body", o.Content); err != nil { 118 return err 119 } 120 121 return nil 122 } 123 124 func (o *AddCommentToTaskBody) validateUserID(formats strfmt.Registry) error { 125 126 if err := validate.Required("body"+"."+"userId", "body", o.UserID); err != nil { 127 return err 128 } 129 130 return nil 131 } 132 133 // ContextValidate validates this add comment to task body based on context it is used 134 func (o *AddCommentToTaskBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 135 return nil 136 } 137 138 // MarshalBinary interface implementation 139 func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) { 140 if o == nil { 141 return nil, nil 142 } 143 return swag.WriteJSON(o) 144 } 145 146 // UnmarshalBinary interface implementation 147 func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error { 148 var res AddCommentToTaskBody 149 if err := swag.ReadJSON(b, &res); err != nil { 150 return err 151 } 152 *o = res 153 return nil 154 }