MCPcopy Index your code
hub / github.com/mpolden/echoip / JSONHandler

Method JSONHandler

http/http.go:258–270  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

256}
257
258func (s *Server) JSONHandler(w http.ResponseWriter, r *http.Request) *appError {
259 response, err := s.newResponse(r)
260 if err != nil {
261 return badRequest(err).WithMessage(err.Error()).AsJSON()
262 }
263 b, err := json.MarshalIndent(response, "", " ")
264 if err != nil {
265 return internalServerError(err).AsJSON()
266 }
267 w.Header().Set("Content-Type", jsonMediaType)
268 w.Write(b)
269 return nil
270}
271
272func (s *Server) HealthHandler(w http.ResponseWriter, r *http.Request) *appError {
273 w.Header().Set("Content-Type", jsonMediaType)

Callers

nothing calls this directly

Calls 7

newResponseMethod · 0.95
badRequestFunction · 0.85
internalServerErrorFunction · 0.85
AsJSONMethod · 0.80
WithMessageMethod · 0.80
HeaderMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected