RenderHTTPResponse either responds with json or a rendered html page using the passed in template by checking the Accepts header
(w http.ResponseWriter, v httpResponse, t *template.Template, r *http.Request)
| 213 | // RenderHTTPResponse either responds with json or a rendered html page using the passed in template |
| 214 | // by checking the Accepts header |
| 215 | func renderHTTPResponse(w http.ResponseWriter, v httpResponse, t *template.Template, r *http.Request) { |
| 216 | accept := r.Header.Get("Accept") |
| 217 | if strings.Contains(accept, "application/json") { |
| 218 | writeJSONResponse(w, v) |
| 219 | return |
| 220 | } |
| 221 | |
| 222 | err := t.Execute(w, v) |
| 223 | if err != nil { |
| 224 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | // WriteJSONResponse writes some JSON as a HTTP response. |
| 229 | func writeJSONResponse(w http.ResponseWriter, v httpResponse) { |
no test coverage detected