FormFieldBinder creates form field value binder For all requests, FormFieldBinder parses the raw query from the URL and uses query params as form fields For POST, PUT, and PATCH requests, it also reads the request body, parses it as a form and uses query params as form fields. Request body paramete
(c *Context)
| 166 | // which parses form data from BOTH URL and BODY if content type is not MIMEMultipartForm |
| 167 | // See https://golang.org/pkg/net/http/#Request.ParseForm |
| 168 | func FormFieldBinder(c *Context) *ValueBinder { |
| 169 | vb := &ValueBinder{ |
| 170 | failFast: true, |
| 171 | ValueFunc: func(sourceParam string) string { |
| 172 | return c.Request().FormValue(sourceParam) |
| 173 | }, |
| 174 | ErrorFunc: NewBindingError, |
| 175 | } |
| 176 | vb.ValuesFunc = func(sourceParam string) []string { |
| 177 | if c.Request().Form == nil { |
| 178 | // this is same as `Request().FormValue()` does internally |
| 179 | _, _ = c.MultipartForm() // we want to trigger c.request.ParseMultipartForm(c.formParseMaxMemory) |
| 180 | } |
| 181 | values, ok := c.Request().Form[sourceParam] |
| 182 | if !ok { |
| 183 | return nil |
| 184 | } |
| 185 | return values |
| 186 | } |
| 187 | |
| 188 | return vb |
| 189 | } |
| 190 | |
| 191 | // FailFast set internal flag to indicate if binding methods will return early (without binding) when previous bind failed |
| 192 | // NB: call this method before any other binding methods as it modifies binding methods behaviour |
searching dependent graphs…