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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user