From 61d72cfc5b221a62113bf2ea302b5d85ce1b1586 Mon Sep 17 00:00:00 2001 From: Sebastien Laithier Date: Wed, 10 May 2023 15:43:53 +0200 Subject: [PATCH] Adding healthcheck handler --- main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b65af72..5b44775 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,7 @@ func PurgeHandler(w http.ResponseWriter, r *http.Request) { url := r.URL.String() status := SendToVarnish(url) if status != "200 Purged" { - w.WriteHeader(http.StatusMethodNotAllowed) + w.WriteHeader(405) } io.WriteString(w, status) } @@ -63,7 +63,13 @@ func SendToVarnish(url string) string { return status } +// HealthHandler handles healthcheck requests and return 200. +func HealthHandler(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "OK") +} + func main() { http.HandleFunc("/", PurgeHandler) + http.HandleFunc("/healthcheck", HealthHandler) log.Fatal(http.ListenAndServe(":6081",nil)) }