diff options
author | Matthew Lemon <y@yulqen.org> | 2024-03-12 14:48:48 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-03-12 14:48:48 +0000 |
commit | 6cf68f633d43b710ab9aa59948101f54b75593f7 (patch) | |
tree | afcbb5c48a53dd529bab157b63c99d337a710777 /cmd/api/helpers.go | |
parent | cb1a75bd57d5a240a80f3fbcf980d386878c0530 (diff) |
Wraps the JSON response in an envelope
Diffstat (limited to 'cmd/api/helpers.go')
-rw-r--r-- | cmd/api/helpers.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/cmd/api/helpers.go b/cmd/api/helpers.go index 61aeb4f..8f30682 100644 --- a/cmd/api/helpers.go +++ b/cmd/api/helpers.go @@ -5,10 +5,13 @@ import ( "net/http" ) +// We want this so that our JSON is nested under a key at the top, e.g. "datamap:"... +type envelope map[string]interface{} + // writeJSON)Pretty() helper for sending responses - pretty prints output. This takes the destination http.ResponseWriter, the // HTTP status code to sned, 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) writeJSONPretty(w http.ResponseWriter, status int, data any, headers http.Header) error { +func (app *application) writeJSONPretty(w http.ResponseWriter, status int, data envelope, headers http.Header) error { // Encode the data to JSON, returing the error if there was one. js, err := json.MarshalIndent(data, "", "\t") if err != nil { |