Updating writeJSON helper method replacing json.Marshal() by json.MarshalIndent() method to improve responses readability. Updating README adding Performance sub-section.

This commit is contained in:
Maxime Delporte
2025-10-19 11:34:42 +02:00
parent 9a0cb4db10
commit d7ccef3713
2 changed files with 13 additions and 3 deletions

View File

@@ -49,8 +49,11 @@ http.ResponseWriter, the HTTP status code to send, the data to encode to JSON, a
header map containing any additional HTTP headers we want to include in the response.
*/
func (app *application) writeJSON(w http.ResponseWriter, status int, data any, headers http.Header) error {
// Encode the data to JSON, returning the error if there was one.
js, err := json.Marshal(data)
/*
Use the json.MarshalIndent() function so that whitespace is added to
the encoded JSON. Here we use no line prefix ("") and tab indents ("\t") for each element.
*/
js, err := json.MarshalIndent(data, "", "\t")
if err != nil {
return err
}