pretty-print API json responses

This commit is contained in:
ari melody 2024-12-02 12:47:42 +00:00
parent fdfc6b8c3e
commit ff6d157e6b
Signed by: ari
GPG key ID: CF99829C92678188
3 changed files with 24 additions and 8 deletions

View file

@ -27,7 +27,9 @@ func ServeAllArtists() http.Handler {
}
w.Header().Add("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(artists)
encoder := json.NewEncoder(w)
encoder.SetIndent("", "\t")
err = encoder.Encode(artists)
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
@ -74,7 +76,9 @@ func ServeArtist(artist *model.Artist) http.Handler {
}
w.Header().Add("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(artistJSON{
encoder := json.NewEncoder(w)
encoder.SetIndent("", "\t")
err = encoder.Encode(artistJSON{
Artist: artist,
Credits: credits,
})