ReadRequest parses the request body based on Content-Type and decodes it into the given RequestObject.
(r *http.Request, i RequestObject)
| 131 | // ReadRequest parses the request body based on Content-Type and |
| 132 | // decodes it into the given RequestObject. |
| 133 | func ReadRequest(r *http.Request, i RequestObject) error { |
| 134 | |
| 135 | // Only parse body for methods that typically include a body |
| 136 | if shouldParseBody(r.Method) { |
| 137 | if err := decodeBody(r, i); err != nil { |
| 138 | return err |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | // Bind fields |
| 143 | if err := i.Bind(r); err != nil { |
| 144 | return errutil.Explain(err, "bind fields error") |
| 145 | } |
| 146 | |
| 147 | // Validate fields |
| 148 | if err := i.Validate(); err != nil { |
| 149 | return errutil.Explain(err, "validate error") |
| 150 | } |
| 151 | return nil |
| 152 | } |
| 153 | |
| 154 | type JSONHandler[Req any, Resp any] func(context.Context, Req) Resp |
| 155 |
no test coverage detected