ReadURL is a shortcut of ReadParams and ReadQuery. It binds dynamic path parameters and URL query parameters to the "ptr" pointer struct value. The struct fields may contain "url" or "param" binding tags. If a validator exists then it validates the result too.
(ptr interface{})
| 3184 | // The struct fields may contain "url" or "param" binding tags. |
| 3185 | // If a validator exists then it validates the result too. |
| 3186 | func (ctx *Context) ReadURL(ptr interface{}) error { |
| 3187 | values := make(map[string][]string, ctx.params.Len()) |
| 3188 | ctx.params.Visit(func(key string, value string) { |
| 3189 | values[key] = strings.Split(value, "/") |
| 3190 | }) |
| 3191 | |
| 3192 | for k, v := range ctx.getQuery() { |
| 3193 | values[k] = append(values[k], v...) |
| 3194 | } |
| 3195 | |
| 3196 | // Decode using all available binding tags (url, header, param). |
| 3197 | err := schema.Decode(values, ptr) |
| 3198 | if err != nil { |
| 3199 | return err |
| 3200 | } |
| 3201 | |
| 3202 | return ctx.app.Validate(ptr) |
| 3203 | } |
| 3204 | |
| 3205 | // ReadProtobuf binds the body to the "ptr" of a proto Message and returns any error. |
| 3206 | // Look `ReadJSONProtobuf` too. |