writeJSONBytes write jsonBytes to response if err is nil otherwise respond with a ErrFailedToJSONMarshalResponseBody.
(w http.ResponseWriter, jsonBytes []byte, err error, code int)
| 74 | // writeJSONBytes write jsonBytes to response if err is nil otherwise respond |
| 75 | // with a ErrFailedToJSONMarshalResponseBody. |
| 76 | func 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. |
| 88 | func RespondWithJSONBytes(w http.ResponseWriter, jsonBytes []byte, err error) { |
no test coverage detected