RenderHTTPResponse either responds with json or a rendered html page using the passed in template by checking the Accepts header
(w http.ResponseWriter, v any, t *template.Template, r *http.Request)
| 100 | // RenderHTTPResponse either responds with json or a rendered html page using the passed in template |
| 101 | // by checking the Accepts header |
| 102 | func RenderHTTPResponse(w http.ResponseWriter, v any, t *template.Template, r *http.Request) { |
| 103 | accept := r.Header.Get("Accept") |
| 104 | if strings.Contains(accept, "application/json") { |
| 105 | WriteJSONResponse(w, v) |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | err := t.Execute(w, v) |
| 110 | if err != nil { |
| 111 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | // StreamWriteYAMLResponseCommon stream writes data as http response |
| 116 | func streamWriteYAMLResponseCommon(w http.ResponseWriter, iter chan any, logger log.Logger, marshalFn func(in any) (out []byte, err error)) { |