aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/api/datamaps.go2
-rw-r--r--cmd/api/helpers.go5
2 files changed, 5 insertions, 2 deletions
diff --git a/cmd/api/datamaps.go b/cmd/api/datamaps.go
index 5133911..c58d811 100644
--- a/cmd/api/datamaps.go
+++ b/cmd/api/datamaps.go
@@ -74,7 +74,7 @@ func (app *application) createDatamapHandler(w http.ResponseWriter, r *http.Requ
}
dm = datamap{Name: dmName, Description: dmDesc, Created: time.Now(), DMLs: dmls}
- err = app.writeJSONPretty(w, http.StatusOK, dm, nil)
+ err = app.writeJSONPretty(w, http.StatusOK, envelope{"datamap": dm}, nil)
if err != nil {
app.logger.Debug("writing out csv", "err", err)
http.Error(w, "Cannot write output from parsed CSV", http.StatusInternalServerError)
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 {