MCPcopy Index your code
hub / github.com/go-spring/go-spring / ReadRequest

Function ReadRequest

stdlib/httpsvr/handler.go:133–152  ·  view source on GitHub ↗

ReadRequest parses the request body based on Content-Type and decodes it into the given RequestObject.

(r *http.Request, i RequestObject)

Source from the content-addressed store, hash-verified

131// ReadRequest parses the request body based on Content-Type and
132// decodes it into the given RequestObject.
133func 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
154type JSONHandler[Req any, Resp any] func(context.Context, Req) Resp
155

Callers 2

HandleJSONFunction · 0.70
HandleStreamFunction · 0.70

Calls 4

shouldParseBodyFunction · 0.85
decodeBodyFunction · 0.85
BindMethod · 0.65
ValidateMethod · 0.65

Tested by

no test coverage detected