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

Function writeJSONResponse

pkg/ring/http.go:229–242  ·  view source on GitHub ↗

WriteJSONResponse writes some JSON as a HTTP response.

(w http.ResponseWriter, v httpResponse)

Source from the content-addressed store, hash-verified

227
228// WriteJSONResponse writes some JSON as a HTTP response.
229func writeJSONResponse(w http.ResponseWriter, v httpResponse) {
230 w.Header().Set("Content-Type", "application/json")
231
232 data, err := json.Marshal(v)
233 if err != nil {
234 http.Error(w, err.Error(), http.StatusInternalServerError)
235 return
236 }
237
238 // We ignore errors here, because we cannot do anything about them.
239 // Write will trigger sending Status code, so we cannot send a different status code afterwards.
240 // Also this isn't internal error, but error communicating with client.
241 _, _ = w.Write(data)
242}

Callers 1

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