Adding healthcheck handler

This commit is contained in:
Sebastien Laithier 2023-05-10 15:43:53 +02:00
parent fe42c2e3d4
commit 61d72cfc5b

View File

@ -33,7 +33,7 @@ func PurgeHandler(w http.ResponseWriter, r *http.Request) {
url := r.URL.String() url := r.URL.String()
status := SendToVarnish(url) status := SendToVarnish(url)
if status != "200 Purged" { if status != "200 Purged" {
w.WriteHeader(http.StatusMethodNotAllowed) w.WriteHeader(405)
} }
io.WriteString(w, status) io.WriteString(w, status)
} }
@ -63,7 +63,13 @@ func SendToVarnish(url string) string {
return status return status
} }
// HealthHandler handles healthcheck requests and return 200.
func HealthHandler(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "OK")
}
func main() { func main() {
http.HandleFunc("/", PurgeHandler) http.HandleFunc("/", PurgeHandler)
http.HandleFunc("/healthcheck", HealthHandler)
log.Fatal(http.ListenAndServe(":6081",nil)) log.Fatal(http.ListenAndServe(":6081",nil))
} }