MCPcopy Index your code
hub / github.com/stefanprodan/podinfo / JSONResponseCode

Method JSONResponseCode

pkg/api/http/http.go:59–71  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, result interface{}, responseCode int)

Source from the content-addressed store, hash-verified

57}
58
59func (s *Server) JSONResponseCode(w http.ResponseWriter, r *http.Request, result interface{}, responseCode int) {
60 body, err := json.Marshal(result)
61 if err != nil {
62 w.WriteHeader(http.StatusInternalServerError)
63 s.logger.Error("JSON marshal failed", zap.Error(err))
64 return
65 }
66
67 w.Header().Set("Content-Type", "application/json; charset=utf-8")
68 w.Header().Set("X-Content-Type-Options", "nosniff")
69 w.WriteHeader(responseCode)
70 w.Write(prettyJSON(body))
71}
72
73func (s *Server) ErrorResponse(w http.ResponseWriter, r *http.Request, span trace.Span, error string, code int) {
74 data := struct {

Callers 4

statusHandlerMethod · 0.95
storeWriteHandlerMethod · 0.95

Calls 3

prettyJSONFunction · 0.85
WriteHeaderMethod · 0.80
HeaderMethod · 0.65

Tested by

no test coverage detected