MCPcopy Index your code
hub / github.com/golang/example / readRequestJSON

Function readRequestJSON

ragserver/ragserver/json.go:17–30  ·  view source on GitHub ↗

readRequestJSON expects req to have a JSON content type with a body that contains a JSON-encoded value complying with the underlying type of target. It populates target, or returns an error.

(req *http.Request, target any)

Source from the content-addressed store, hash-verified

15// contains a JSON-encoded value complying with the underlying type of target.
16// It populates target, or returns an error.
17func readRequestJSON(req *http.Request, target any) error {
18 contentType := req.Header.Get("Content-Type")
19 mediaType, _, err := mime.ParseMediaType(contentType)
20 if err != nil {
21 return err
22 }
23 if mediaType != "application/json" {
24 return fmt.Errorf("expect application/json Content-Type, got %s", mediaType)
25 }
26
27 dec := json.NewDecoder(req.Body)
28 dec.DisallowUnknownFields()
29 return dec.Decode(target)
30}
31
32// renderJSON renders 'v' as JSON and writes it as a response into w.
33func renderJSON(w http.ResponseWriter, v any) {

Callers 2

addDocumentsHandlerMethod · 0.70
queryHandlerMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…