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

Function renderHTTPResponse

ring/ring_http.go:167–178  ·  view source on GitHub ↗

RenderHTTPResponse either responds with json or a rendered html page using the passed in template by checking the Accepts header

(w http.ResponseWriter, v any, t *template.Template, r *http.Request)

Source from the content-addressed store, hash-verified

165// RenderHTTPResponse either responds with json or a rendered html page using the passed in template
166// by checking the Accepts header
167func renderHTTPResponse(w http.ResponseWriter, v any, t *template.Template, r *http.Request) {
168 accept := r.Header.Get("Accept")
169 if strings.Contains(accept, "application/json") {
170 writeJSONResponse(w, v)
171 return
172 }
173
174 w.Header().Set("Content-Type", "text/html")
175 if err := t.Execute(w, v); err != nil {
176 http.Error(w, err.Error(), http.StatusInternalServerError)
177 }
178}
179
180func (h *ringPageHandler) forget(ctx context.Context, id string) error {
181 unregister := func(in interface{}) (out interface{}, retry bool, err error) {

Callers 2

handleMethod · 0.85
handleGetRequestMethod · 0.85

Calls 5

writeJSONResponseFunction · 0.85
GetMethod · 0.65
SetMethod · 0.65
HeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected