MCPcopy Index your code
hub / github.com/cortexproject/cortex / WriteJSONResponse

Function WriteJSONResponse

pkg/util/http.go:51–64  ·  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

49
50// WriteJSONResponse writes some JSON as a HTTP response.
51func WriteJSONResponse(w http.ResponseWriter, v any) {
52 w.Header().Set("Content-Type", "application/json")
53
54 data, err := json.Marshal(v)
55 if err != nil {
56 http.Error(w, err.Error(), http.StatusInternalServerError)
57 return
58 }
59
60 // We ignore errors here, because we cannot do anything about them.
61 // Write will trigger sending Status code, so we cannot send a different status code afterwards.
62 // Also this isn't internal error, but error communicating with client.
63 _, _ = w.Write(data)
64}
65
66// WriteYAMLResponse writes some YAML as a HTTP response.
67func WriteYAMLResponse(w http.ResponseWriter, v any) {

Callers 6

DeleteTenantStatusMethod · 0.92
UserStatsHandlerMethod · 0.92
MetadataHandlerFunction · 0.92
validateLimitsFunction · 0.92
RenderHTTPResponseFunction · 0.85

Calls 5

SetMethod · 0.65
HeaderMethod · 0.45
MarshalMethod · 0.45
ErrorMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected