github.com/djarvur/go-swagger@v0.18.0/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 "net/http" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/runtime" 13 "github.com/go-openapi/runtime/middleware" 14 15 strfmt "github.com/go-openapi/strfmt" 16 17 models "github.com/go-swagger/go-swagger/examples/todo-list/models" 18 ) 19 20 // NewUpdateOneParams creates a new UpdateOneParams object 21 // no default values defined in spec. 22 func NewUpdateOneParams() UpdateOneParams { 23 24 return UpdateOneParams{} 25 } 26 27 // UpdateOneParams contains all the bound params for the update one operation 28 // typically these are obtained from a http.Request 29 // 30 // swagger:parameters updateOne 31 type UpdateOneParams struct { 32 33 // HTTP Request Object 34 HTTPRequest *http.Request `json:"-"` 35 36 /* 37 In: body 38 */ 39 Body *models.Item 40 /* 41 Required: true 42 In: path 43 */ 44 ID string 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 NewUpdateOneParams() beforehand. 51 func (o *UpdateOneParams) 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 models.Item 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 if len(res) == 0 { 68 o.Body = &body 69 } 70 } 71 } 72 rID, rhkID, _ := route.Params.GetOK("id") 73 if err := o.bindID(rID, rhkID, route.Formats); err != nil { 74 res = append(res, err) 75 } 76 77 if len(res) > 0 { 78 return errors.CompositeValidationError(res...) 79 } 80 return nil 81 } 82 83 // bindID binds and validates parameter ID from path. 84 func (o *UpdateOneParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { 85 var raw string 86 if len(rawData) > 0 { 87 raw = rawData[len(rawData)-1] 88 } 89 90 // Required: true 91 // Parameter is provided by construction from the route 92 93 o.ID = raw 94 95 return nil 96 }