github.com/circl-dev/go-swagger@v0.31.0/examples/todo-list-strict/restapi/operations/todos/find_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 "fmt" 10 "net/http" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/circl-dev/runtime" 16 "github.com/circl-dev/runtime/middleware" 17 "github.com/circl-dev/validate" 18 ) 19 20 // NewFindParams creates a new FindParams object 21 // no default values defined in spec. 22 func NewFindParams() FindParams { 23 24 return FindParams{} 25 } 26 27 // FindParams contains all the bound params for the find operation 28 // typically these are obtained from a http.Request 29 // 30 // swagger:parameters find 31 type FindParams struct { 32 33 // HTTP Request Object 34 HTTPRequest *http.Request `json:"-"` 35 36 /* 37 Required: true 38 In: header 39 */ 40 XRateLimit int32 41 /* 42 Required: true 43 In: formData 44 */ 45 Limit int32 46 /* 47 Required: true 48 In: formData 49 Collection Format: multi 50 */ 51 Tags []int32 52 } 53 54 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 55 // for simple values it will use straight method calls. 56 // 57 // To ensure default values, the struct must have been initialized with NewFindParams() beforehand. 58 func (o *FindParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 59 var res []error 60 61 o.HTTPRequest = r 62 63 if err := r.ParseMultipartForm(32 << 20); err != nil { 64 if err != http.ErrNotMultipart { 65 return errors.New(400, "%v", err) 66 } else if err := r.ParseForm(); err != nil { 67 return errors.New(400, "%v", err) 68 } 69 } 70 fds := runtime.Values(r.Form) 71 72 if err := o.bindXRateLimit(r.Header[http.CanonicalHeaderKey("X-Rate-Limit")], true, route.Formats); err != nil { 73 res = append(res, err) 74 } 75 76 fdLimit, fdhkLimit, _ := fds.GetOK("limit") 77 if err := o.bindLimit(fdLimit, fdhkLimit, route.Formats); err != nil { 78 res = append(res, err) 79 } 80 81 fdTags, fdhkTags, _ := fds.GetOK("tags") 82 if err := o.bindTags(fdTags, fdhkTags, route.Formats); err != nil { 83 res = append(res, err) 84 } 85 86 if len(res) > 0 { 87 return errors.CompositeValidationError(res...) 88 } 89 return nil 90 } 91 92 // bindXRateLimit binds and validates parameter XRateLimit from header. 93 func (o *FindParams) bindXRateLimit(rawData []string, hasKey bool, formats strfmt.Registry) error { 94 if !hasKey { 95 return errors.Required("X-Rate-Limit", "header", rawData) 96 } 97 var raw string 98 if len(rawData) > 0 { 99 raw = rawData[len(rawData)-1] 100 } 101 102 // Required: true 103 104 if err := validate.RequiredString("X-Rate-Limit", "header", raw); err != nil { 105 return err 106 } 107 108 value, err := swag.ConvertInt32(raw) 109 if err != nil { 110 return errors.InvalidType("X-Rate-Limit", "header", "int32", raw) 111 } 112 o.XRateLimit = value 113 114 return nil 115 } 116 117 // bindLimit binds and validates parameter Limit from formData. 118 func (o *FindParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error { 119 if !hasKey { 120 return errors.Required("limit", "formData", rawData) 121 } 122 var raw string 123 if len(rawData) > 0 { 124 raw = rawData[len(rawData)-1] 125 } 126 127 // Required: true 128 129 if raw == "" { // empty values pass all other validations 130 return nil 131 } 132 133 value, err := swag.ConvertInt32(raw) 134 if err != nil { 135 return errors.InvalidType("limit", "formData", "int32", raw) 136 } 137 o.Limit = value 138 139 return nil 140 } 141 142 // bindTags binds and validates array parameter Tags from formData. 143 // 144 // Arrays are parsed according to CollectionFormat: "multi" (defaults to "csv" when empty). 145 func (o *FindParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error { 146 if !hasKey { 147 return errors.Required("tags", "formData", rawData) 148 } 149 150 // CollectionFormat: multi 151 tagsIC := rawData 152 153 if len(tagsIC) == 0 { 154 return nil 155 } 156 157 var tagsIR []int32 158 for i, tagsIV := range tagsIC { 159 // items.Format: "int32" 160 tagsI, err := swag.ConvertInt32(tagsIV) 161 if err != nil { 162 return errors.InvalidType(fmt.Sprintf("%s.%v", "tags", i), "formData", "int32", tagsI) 163 } 164 165 tagsIR = append(tagsIR, tagsI) 166 } 167 168 o.Tags = tagsIR 169 170 return nil 171 }