MCPcopy
hub / github.com/uber/aresdb / writeJSONBytes

Function writeJSONBytes

api/common/response.go:76–85  ·  view source on GitHub ↗

writeJSONBytes write jsonBytes to response if err is nil otherwise respond with a ErrFailedToJSONMarshalResponseBody.

(w http.ResponseWriter, jsonBytes []byte, err error, code int)

Source from the content-addressed store, hash-verified

74// writeJSONBytes write jsonBytes to response if err is nil otherwise respond
75// with a ErrFailedToJSONMarshalResponseBody.
76func writeJSONBytes(w http.ResponseWriter, jsonBytes []byte, err error, code int) {
77 if err != nil {
78 RespondWithError(w, ErrFailedToJSONMarshalResponseBody)
79 }
80 w.Header().Set("Content-Type", "application/json")
81 w.WriteHeader(code)
82 if jsonBytes != nil {
83 w.Write(jsonBytes)
84 }
85}
86
87// RespondWithJSONBytes writes json bytes to response.
88func RespondWithJSONBytes(w http.ResponseWriter, jsonBytes []byte, err error) {

Callers 2

RespondWithJSONBytesFunction · 0.85

Calls 5

RespondWithErrorFunction · 0.85
WriteHeaderMethod · 0.80
WriteMethod · 0.65
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected