Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
Oliver Davies 2025-09-20 23:41:05 +01:00
parent fe620bc9d9
commit 6b5592a10c

View file

@ -7,6 +7,15 @@ import (
"strconv" "strconv"
) )
type ErrorResponse struct {
Message string `json:"message"`
StatusCode int `json:"statusCode"`
}
type SuccessResponse struct {
Name string `json:"name"`
}
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Running handler...") fmt.Println("Running handler...")
@ -16,13 +25,13 @@ func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
if (code != 200) { if (code != 200) {
json.NewEncoder(w).Encode(map[string]any{ json.NewEncoder(w).Encode(ErrorResponse{
"message": "There has been an error.", Message: "There has been an error.",
"statusCode": code, StatusCode: code,
}) })
} else { } else {
json.NewEncoder(w).Encode(map[string]string{ json.NewEncoder(w).Encode(SuccessResponse{
"name": "Oliver Davies", Name: "Oliver Davies",
}) })
} }
} }