github.com/circl-dev/go-swagger@v0.31.0/examples/generated/restapi/operations/user/update_user_parameters.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package user 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/strfmt" 14 "github.com/circl-dev/runtime" 15 "github.com/circl-dev/runtime/middleware" 16 "github.com/circl-dev/validate" 17 18 "github.com/circl-dev/go-swagger/examples/generated/models" 19 ) 20 21 // NewUpdateUserParams creates a new UpdateUserParams object 22 // 23 // There are no default values defined in the spec. 24 func NewUpdateUserParams() UpdateUserParams { 25 26 return UpdateUserParams{} 27 } 28 29 // UpdateUserParams contains all the bound params for the update user operation 30 // typically these are obtained from a http.Request 31 // 32 // swagger:parameters updateUser 33 type UpdateUserParams struct { 34 35 // HTTP Request Object 36 HTTPRequest *http.Request `json:"-"` 37 38 /*Updated user object 39 In: body 40 */ 41 Body *models.User 42 /*name that need to be deleted 43 Required: true 44 In: path 45 */ 46 Username 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 NewUpdateUserParams() beforehand. 53 func (o *UpdateUserParams) 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.User 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 rUsername, rhkUsername, _ := route.Params.GetOK("username") 81 if err := o.bindUsername(rUsername, rhkUsername, 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 // bindUsername binds and validates parameter Username from path. 91 func (o *UpdateUserParams) bindUsername(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.Username = raw 100 101 return nil 102 }