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

Method Wrap

pkg/api/queryapi/query_api.go:227–251  ·  view source on GitHub ↗
(f apiFunc)

Source from the content-addressed store, hash-verified

225}
226
227func (q *QueryAPI) Wrap(f apiFunc) http.HandlerFunc {
228 hf := func(w http.ResponseWriter, r *http.Request) {
229 httputil.SetCORS(w, q.CORSOrigin, r)
230
231 result := f(r)
232 if result.finalizer != nil {
233 defer result.finalizer()
234 }
235
236 if result.err != nil {
237 api.RespondFromGRPCError(q.logger, w, result.err.err)
238 return
239 }
240
241 if result.data != nil {
242 q.respond(w, r, result.data, result.warnings, r.FormValue("query"))
243 return
244 }
245 w.WriteHeader(http.StatusNoContent)
246 }
247
248 return CompressionHandler{
249 Handler: http.HandlerFunc(hf),
250 }.ServeHTTP
251}
252
253func (q *QueryAPI) respond(w http.ResponseWriter, req *http.Request, data any, warnings annotations.Annotations, query string) {
254 warn, info := warnings.AsStrings(query, 10, 10)

Callers 5

NewQuerierHandlerFunction · 0.95
Test_CustomAPIFunction · 0.95
Test_InvalidCodecFunction · 0.95

Calls 2

respondMethod · 0.95
RespondFromGRPCErrorFunction · 0.92

Tested by 4

Test_CustomAPIFunction · 0.76
Test_InvalidCodecFunction · 0.76