From ef183ab1ceb5626d3f800891b67d2d4ff6484bbc Mon Sep 17 00:00:00 2001 From: Cody Couperus Date: Thu, 12 Feb 2026 23:28:10 -0800 Subject: [PATCH] add health route --- main.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/main.go b/main.go index b2fce74..ad33b32 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,10 @@ type Reading struct { FetchedAt time.Time `json:"fetched_at"` } +type HealthResponse struct { + Status string `json:"status"` +} + func getEnv(key string) string { val := os.Getenv(key) if val == "" { @@ -243,6 +247,19 @@ func main() { }) }) + // GET /health + http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { + // TODO: Check if database is ready as well + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + okStatus := HealthResponse{Status: "ok"} + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(okStatus) + }) + // GET /weather/history?city=London&limit=10 http.HandleFunc("/weather/history", func(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet {