WriteJSONResponse writes some JSON as a HTTP response.
(w http.ResponseWriter, v httpResponse)
| 227 | |
| 228 | // WriteJSONResponse writes some JSON as a HTTP response. |
| 229 | func writeJSONResponse(w http.ResponseWriter, v httpResponse) { |
| 230 | w.Header().Set("Content-Type", "application/json") |
| 231 | |
| 232 | data, err := json.Marshal(v) |
| 233 | if err != nil { |
| 234 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | // We ignore errors here, because we cannot do anything about them. |
| 239 | // Write will trigger sending Status code, so we cannot send a different status code afterwards. |
| 240 | // Also this isn't internal error, but error communicating with client. |
| 241 | _, _ = w.Write(data) |
| 242 | } |