MCPcopy
hub / github.com/grafana/dskit / writeJSONResponse

Function writeJSONResponse

ring/ring_http.go:194–200  ·  view source on GitHub ↗

WriteJSONResponse writes some JSON as a HTTP response.

(w http.ResponseWriter, v any)

Source from the content-addressed store, hash-verified

192
193// WriteJSONResponse writes some JSON as a HTTP response.
194func writeJSONResponse(w http.ResponseWriter, v any) {
195 w.Header().Set("Content-Type", "application/json")
196
197 if err := json.NewEncoder(w).Encode(v); err != nil {
198 http.Error(w, err.Error(), http.StatusInternalServerError)
199 }
200}

Callers 1

renderHTTPResponseFunction · 0.85

Calls 4

SetMethod · 0.65
EncodeMethod · 0.65
HeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected