MCPcopy Index your code
hub / github.com/perkeep/perkeep / ReturnJSONCode

Function ReturnJSONCode

internal/httputil/httputil.go:76–87  ·  view source on GitHub ↗
(rw http.ResponseWriter, code int, data interface{})

Source from the content-addressed store, hash-verified

74}
75
76func ReturnJSONCode(rw http.ResponseWriter, code int, data interface{}) {
77 js, err := json.MarshalIndent(data, "", " ")
78 if err != nil {
79 BadRequestError(rw, "JSON serialization error: %v", err)
80 return
81 }
82 rw.Header().Set("Content-Type", "text/javascript")
83 rw.Header().Set("Content-Length", strconv.Itoa(len(js)+1))
84 rw.WriteHeader(code)
85 rw.Write(js)
86 rw.Write([]byte("\n"))
87}
88
89// PrefixHandler wraps another Handler and verifies that all requests'
90// Path begin with Prefix. If they don't, a 500 error is returned.

Callers 3

handleRemoveFunction · 0.92
ReturnJSONFunction · 0.85
ServeJSONErrorFunction · 0.85

Calls 4

BadRequestErrorFunction · 0.85
SetMethod · 0.65
WriteHeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected