From 075bbaac5ee08004e6d4f049d12c084a0e076233 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 20 Sep 2025 23:33:48 +0100 Subject: [PATCH] Return a JSON object if the response is successful Signed-off-by: Oliver Davies --- go-api/main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/go-api/main.go b/go-api/main.go index f560e30..82d09a1 100644 --- a/go-api/main.go +++ b/go-api/main.go @@ -10,9 +10,18 @@ import ( func handler(w http.ResponseWriter, r *http.Request) { fmt.Println("Running handler...") - w.WriteHeader(getResponseCode(r)) + code := getResponseCode(r) + + w.WriteHeader(code) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(map[string]any{}) + + if (code != 200) { + json.NewEncoder(w).Encode(map[string]any{}) + } else { + json.NewEncoder(w).Encode(map[string]string{ + "name": "Oliver Davies", + }) + } } func getResponseCode(r *http.Request) int {