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

Function WriteYAMLResponse

pkg/util/http.go:63–78  ·  view source on GitHub ↗

WriteYAMLResponse writes some YAML as a HTTP response.

(w http.ResponseWriter, v interface{})

Source from the content-addressed store, hash-verified

61
62// WriteYAMLResponse writes some YAML as a HTTP response.
63func WriteYAMLResponse(w http.ResponseWriter, v interface{}) {
64 // There is not standardised content-type for YAML, text/plain ensures the
65 // YAML is displayed in the browser instead of offered as a download
66 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
67
68 data, err := yaml.Marshal(v)
69 if err != nil {
70 http.Error(w, err.Error(), http.StatusInternalServerError)
71 return
72 }
73
74 // We ignore errors here, because we cannot do anything about them.
75 // Write will trigger sending Status code, so we cannot send a different status code afterwards.
76 // Also this isn't internal error, but error communicating with client.
77 _, _ = w.Write(data)
78}
79
80// Sends message as text/plain response with 200 status code.
81func WriteTextResponse(w http.ResponseWriter, message string) {

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected