github.com/emreu/go-swagger@v0.22.1/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 "net/http" 10 11 errors "github.com/go-openapi/errors" 12 middleware "github.com/go-openapi/runtime/middleware" 13 strfmt "github.com/go-openapi/strfmt" 14 swag "github.com/go-openapi/swag" 15 validate "github.com/go-openapi/validate" 16 ) 17 18 // AddCommentToTaskHandlerFunc turns a function with the right signature into a add comment to task handler 19 type AddCommentToTaskHandlerFunc func(AddCommentToTaskParams, interface{}) middleware.Responder 20 21 // Handle executing the request and returning a response 22 func (fn AddCommentToTaskHandlerFunc) Handle(params AddCommentToTaskParams, principal interface{}) middleware.Responder { 23 return fn(params, principal) 24 } 25 26 // AddCommentToTaskHandler interface for that can handle valid add comment to task params 27 type AddCommentToTaskHandler interface { 28 Handle(AddCommentToTaskParams, interface{}) middleware.Responder 29 } 30 31 // NewAddCommentToTask creates a new http.Handler for the add comment to task operation 32 func NewAddCommentToTask(ctx *middleware.Context, handler AddCommentToTaskHandler) *AddCommentToTask { 33 return &AddCommentToTask{Context: ctx, Handler: handler} 34 } 35 36 /*AddCommentToTask swagger:route POST /tasks/{id}/comments tasks addCommentToTask 37 38 Adds a comment to a task 39 40 The comment can contain ___github markdown___ syntax. 41 Fenced codeblocks etc are supported through pygments. 42 43 44 */ 45 type AddCommentToTask struct { 46 Context *middleware.Context 47 Handler AddCommentToTaskHandler 48 } 49 50 func (o *AddCommentToTask) ServeHTTP(rw http.ResponseWriter, r *http.Request) { 51 route, rCtx, _ := o.Context.RouteInfo(r) 52 if rCtx != nil { 53 r = rCtx 54 } 55 var Params = NewAddCommentToTaskParams() 56 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 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 77 o.Context.Respond(rw, r, route.Produces, route, res) 78 79 } 80 81 // AddCommentToTaskBody A comment to create 82 // 83 // These values can have github flavored markdown. 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 // MarshalBinary interface implementation 134 func (o *AddCommentToTaskBody) MarshalBinary() ([]byte, error) { 135 if o == nil { 136 return nil, nil 137 } 138 return swag.WriteJSON(o) 139 } 140 141 // UnmarshalBinary interface implementation 142 func (o *AddCommentToTaskBody) UnmarshalBinary(b []byte) error { 143 var res AddCommentToTaskBody 144 if err := swag.ReadJSON(b, &res); err != nil { 145 return err 146 } 147 *o = res 148 return nil 149 }