MCPcopy
hub / github.com/prometheus/pushgateway / respond

Method respond

api/v1/api.go:170–189  ·  view source on GitHub ↗
(w http.ResponseWriter, data any)

Source from the content-addressed store, hash-verified

168}
169
170func (api *API) respond(w http.ResponseWriter, data any) {
171 w.Header().Set("Content-Type", "application/json")
172 w.WriteHeader(http.StatusOK)
173
174 b, err := json.Marshal(&response{
175 Status: statusSuccess,
176 Data: data,
177 })
178 if err != nil {
179 api.logger.Error("error marshaling JSON", "err", err)
180 api.respondError(w, apiError{
181 typ: errorBadData,
182 err: err,
183 }, "")
184 }
185
186 if _, err := w.Write(b); err != nil {
187 api.logger.Error("failed to write data to connection", "err", err)
188 }
189}
190
191func (api *API) respondError(w http.ResponseWriter, apiErr apiError, data any) {
192 w.Header().Set("Content-Type", "application/json")

Callers 2

metricsMethod · 0.95
statusMethod · 0.95

Calls 2

respondErrorMethod · 0.95
ErrorMethod · 0.80

Tested by

no test coverage detected