StatusJSONResponse turns the given argument into a JSON response. The argument is not meant to be a JSON string, unless it's intentional.
(status int, body interface{})
| 173 | // |
| 174 | // The argument is not meant to be a JSON string, unless it's intentional. |
| 175 | func StatusJSONResponse(status int, body interface{}) Responder { |
| 176 | return func(req *http.Request) (*http.Response, error) { |
| 177 | b, _ := json.Marshal(body) |
| 178 | header := http.Header{ |
| 179 | "Content-Type": []string{"application/json"}, |
| 180 | } |
| 181 | return httpResponseWithHeader(status, req, bytes.NewBuffer(b), header), nil |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | // JSONErrorResponse is a type-safe helper to avoid confusion around the |
| 186 | // provided argument. |