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