github.com/go-swagger/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/create_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 "io" 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/validate" 16 17 "github.com/go-swagger/go-swagger/examples/task-tracker/models" 18 ) 19 20 // NewCreateTaskParams creates a new CreateTaskParams object 21 // 22 // There are no default values defined in the spec. 23 func NewCreateTaskParams() CreateTaskParams { 24 25 return CreateTaskParams{} 26 } 27 28 // CreateTaskParams contains all the bound params for the create task operation 29 // typically these are obtained from a http.Request 30 // 31 // swagger:parameters createTask 32 type CreateTaskParams struct { 33 34 // HTTP Request Object 35 HTTPRequest *http.Request `json:"-"` 36 37 /*The task to create 38 Required: true 39 In: body 40 */ 41 Body *models.Task 42 } 43 44 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 45 // for simple values it will use straight method calls. 46 // 47 // To ensure default values, the struct must have been initialized with NewCreateTaskParams() beforehand. 48 func (o *CreateTaskParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 49 var res []error 50 51 o.HTTPRequest = r 52 53 if runtime.HasBody(r) { 54 defer r.Body.Close() 55 var body models.Task 56 if err := route.Consumer.Consume(r.Body, &body); err != nil { 57 if err == io.EOF { 58 res = append(res, errors.Required("body", "body", "")) 59 } else { 60 res = append(res, errors.NewParseError("body", "body", "", err)) 61 } 62 } else { 63 // validate body object 64 if err := body.Validate(route.Formats); err != nil { 65 res = append(res, err) 66 } 67 68 ctx := validate.WithOperationRequest(r.Context()) 69 if err := body.ContextValidate(ctx, route.Formats); err != nil { 70 res = append(res, err) 71 } 72 73 if len(res) == 0 { 74 o.Body = &body 75 } 76 } 77 } else { 78 res = append(res, errors.Required("body", "body", "")) 79 } 80 if len(res) > 0 { 81 return errors.CompositeValidationError(res...) 82 } 83 return nil 84 }