MCPcopy
hub / github.com/grafana/tempo / WriteJSONResponse

Function WriteJSONResponse

pkg/util/http.go:47–60  ·  view source on GitHub ↗

WriteJSONResponse writes some JSON as a HTTP response.

(w http.ResponseWriter, v interface{})

Source from the content-addressed store, hash-verified

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

Callers 2

RenderHTTPResponseFunction · 0.85

Calls 5

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

Tested by

no test coverage detected