package main import ( "encoding/json" "log" "net/http" ) func main() { http.HandleFunc("/health", healthHandler) log.Println("server listening on http://localhost:8080") if err := http.ListenAndServe(":8080", nil); err != nil { log.Fatal(err) } } func healthHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } w.Header().Set("Content-Type", "application/json") response := map[string]string{ "status": "ok", } if err := json.NewEncoder(w).Encode(response); err != nil { log.Println("failed to encode health response:", err) } }