MCPcopy Create free account
hub / github.com/daodst/chat / UnmarshalJSONRequest

Function UnmarshalJSONRequest

clientapi/httputil/httputil.go:29–40  ·  view source on GitHub ↗

UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if there was a problem unmarshalling. Calling this function consumes the request body.

(req *http.Request, iface interface{})

Source from the content-addressed store, hash-verified

27// UnmarshalJSONRequest into the given interface pointer. Returns an error JSON response if
28// there was a problem unmarshalling. Calling this function consumes the request body.
29func UnmarshalJSONRequest(req *http.Request, iface interface{}) *util.JSONResponse {
30 // encoding/json allows invalid utf-8, matrix does not
31 // https://matrix.org/docs/spec/client_server/r0.6.1#api-standards
32 body, err := io.ReadAll(req.Body)
33 if err != nil {
34 util.GetLogger(req.Context()).WithError(err).Error("io.ReadAll failed")
35 resp := jsonerror.InternalServerError()
36 return &resp
37 }
38
39 return UnmarshalJSON(body, iface)
40}
41
42func UnmarshalJSON(body []byte, iface interface{}) *util.JSONResponse {
43 if !utf8.Valid(body) {

Callers

nothing calls this directly

Calls 3

UnmarshalJSONFunction · 0.85
ContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected