package webutils import ( "encoding/json" "fmt" "net/http" "git.mstar.dev/mstar/goutils/other" ) func SendJson(w http.ResponseWriter, data any) error { encoded, err := json.Marshal(data) if err != nil { return other.Error("webutils.SendJson", "failed to marshal data to json", err) } w.Header().Add("Content-Type", "application/json") // Can't really catch here _, _ = fmt.Fprint(w, string(encoded)) return nil }