Added /health endpoint

This commit is contained in:
Robin Dittmar
2026-07-03 10:01:33 +02:00
parent 4379f8bdda
commit 4afb76cea0
+20
View File
@@ -17,6 +17,10 @@ type ApiResponse struct {
Form map[string]string `json:"form"`
}
type HealthResponse struct {
Status string `json:"status"`
}
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
var resp ApiResponse
@@ -54,6 +58,22 @@ func main() {
}
})
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
resp := HealthResponse{Status: "ok"}
b, err := json.Marshal(&resp)
if err != nil {
log.Println(err)
return
}
_, err = w.Write(b)
if err != nil {
log.Println(err)
return
}
})
fmt.Println("Listening on localhost:8080")
log.Fatal(http.ListenAndServe("localhost:8080", nil))
}