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