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