diff options
Diffstat (limited to 'backend')
-rw-r--r-- | backend/main.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/backend/main.go b/backend/main.go index 3dd9d38..1ed188a 100644 --- a/backend/main.go +++ b/backend/main.go @@ -51,11 +51,10 @@ func RecipeList(w http.ResponseWriter, r *http.Request) { } resp.Data = append(resp.Data, APIDataIds{Ids: ids}) - output, err := json.MarshalIndent(resp, "", " ") - if err != nil { - fmt.Println("Error converting to JSON") - } else { - fmt.Println(string(output)) + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + if err := json.NewEncoder(w).Encode(resp); err != nil { + panic(err) } } } @@ -78,11 +77,10 @@ func SingleRecipe(w http.ResponseWriter, r *http.Request) { } resp.Data = append(resp.Data, APIDataRecipe{recipe}) - output, err := json.MarshalIndent(resp, "", " ") - if err != nil { - fmt.Println("Error converting to JSON") - } else { - fmt.Println(string(output)) + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + if err := json.NewEncoder(w).Encode(resp); err != nil { + panic(err) } } else if r.Method == "POST" { |