package main import ( "encoding/json" "log" "net/http" ) func render[T any](w http.ResponseWriter, r *http.Request, status int, response T) error { if body, err := json.MarshalIndent(response, "", " "); err == nil { w.Header().Add("content-type", "application/json") w.WriteHeader(status) _, err = w.Write(body) return err } else { w.WriteHeader(http.StatusInternalServerError) log.Printf("couldn't parse response") _, err = w.Write([]byte{}) return err } }