Bind implements the `Binder#Bind` function. Binding is done in following order: 1) path params; 2) query params; 3) request body. Each step COULD override previous step bound values. For single source binding use their own methods BindBody, BindQueryParams, BindPathValues.
(c *Context, target any)
| 122 | // Binding is done in following order: 1) path params; 2) query params; 3) request body. Each step COULD override previous |
| 123 | // step bound values. For single source binding use their own methods BindBody, BindQueryParams, BindPathValues. |
| 124 | func (b *DefaultBinder) Bind(c *Context, target any) error { |
| 125 | if err := BindPathValues(c, target); err != nil { |
| 126 | return err |
| 127 | } |
| 128 | // Only bind query parameters for GET/DELETE/HEAD to avoid unexpected behavior with destination struct binding from body. |
| 129 | // For example a request URL `&id=1&lang=en` with body `{"id":100,"lang":"de"}` would lead to precedence issues. |
| 130 | // The HTTP method check restores pre-v4.1.11 behavior to avoid these problems (see issue #1670) |
| 131 | method := c.Request().Method |
| 132 | if method == http.MethodGet || method == http.MethodDelete || method == http.MethodHead { |
| 133 | if err := BindQueryParams(c, target); err != nil { |
| 134 | return err |
| 135 | } |
| 136 | } |
| 137 | return BindBody(c, target) |
| 138 | } |
| 139 | |
| 140 | // bindFieldMeta is the cached, type-level reflection metadata for a single struct field. Reading struct |
| 141 | // tags (reflect.StructTag.Get) parses the tag string on every call, so for binding-heavy endpoints we |
nothing calls this directly
no test coverage detected