github.com/go-swagger/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/add_comment_to_task_parameters.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 swagger generate command 7 8 import ( 9 "net/http" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/runtime" 13 "github.com/go-openapi/runtime/middleware" 14 "github.com/go-openapi/strfmt" 15 "github.com/go-openapi/swag" 16 "github.com/go-openapi/validate" 17 ) 18 19 // NewAddCommentToTaskParams creates a new AddCommentToTaskParams object 20 // 21 // There are no default values defined in the spec. 22 func NewAddCommentToTaskParams() AddCommentToTaskParams { 23 24 return AddCommentToTaskParams{} 25 } 26 27 // AddCommentToTaskParams contains all the bound params for the add comment to task operation 28 // typically these are obtained from a http.Request 29 // 30 // swagger:parameters addCommentToTask 31 type AddCommentToTaskParams struct { 32 33 // HTTP Request Object 34 HTTPRequest *http.Request `json:"-"` 35 36 /*The comment to add 37 In: body 38 */ 39 Body AddCommentToTaskBody 40 /*The id of the item 41 Required: true 42 In: path 43 */ 44 ID int64 45 } 46 47 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 48 // for simple values it will use straight method calls. 49 // 50 // To ensure default values, the struct must have been initialized with NewAddCommentToTaskParams() beforehand. 51 func (o *AddCommentToTaskParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 52 var res []error 53 54 o.HTTPRequest = r 55 56 if runtime.HasBody(r) { 57 defer r.Body.Close() 58 var body AddCommentToTaskBody 59 if err := route.Consumer.Consume(r.Body, &body); err != nil { 60 res = append(res, errors.NewParseError("body", "body", "", err)) 61 } else { 62 // validate body object 63 if err := body.Validate(route.Formats); err != nil { 64 res = append(res, err) 65 } 66 67 ctx := validate.WithOperationRequest(r.Context()) 68 if err := body.ContextValidate(ctx, route.Formats); err != nil { 69 res = append(res, err) 70 } 71 72 if len(res) == 0 { 73 o.Body = body 74 } 75 } 76 } 77 78 rID, rhkID, _ := route.Params.GetOK("id") 79 if err := o.bindID(rID, rhkID, route.Formats); err != nil { 80 res = append(res, err) 81 } 82 if len(res) > 0 { 83 return errors.CompositeValidationError(res...) 84 } 85 return nil 86 } 87 88 // bindID binds and validates parameter ID from path. 89 func (o *AddCommentToTaskParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { 90 var raw string 91 if len(rawData) > 0 { 92 raw = rawData[len(rawData)-1] 93 } 94 95 // Required: true 96 // Parameter is provided by construction from the route 97 98 value, err := swag.ConvertInt64(raw) 99 if err != nil { 100 return errors.InvalidType("id", "path", "int64", raw) 101 } 102 o.ID = value 103 104 return nil 105 }