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