Creating an envelope struct type inside our helpers file to update our writeJSON data type method's parameter. Updating healthcheckHandler and showMovieHandler with this new type to update our responses.
This commit is contained in:
@@ -43,12 +43,14 @@ func (app *application) readIDParam(r *http.Request) (int64, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
type envelope map[string]any
|
||||
|
||||
/*
|
||||
Define a writeJSON() helper for sending responses. This takes the destination
|
||||
http.ResponseWriter, the HTTP status code to send, the data to encode to JSON, and 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 {
|
||||
func (app *application) writeJSON(w http.ResponseWriter, status int, data envelope, headers http.Header) error {
|
||||
/*
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user