From 17924e7bb66c7cc6b2e4bbc2190105ec7fcf89ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 15 Jun 2018 17:07:48 +0200 Subject: [PATCH] add basic healthcheck --- stats.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/stats.go b/stats.go index 17b3e3e..b9ae146 100644 --- a/stats.go +++ b/stats.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "net/http" "time" @@ -36,10 +37,17 @@ func init() { type Stats struct { } +// For verifying the service is up +func healthHandler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "OK") +} + // NewStats returns new empty Stats object. func NewStats(statsPort string) *Stats { go func() { http.Handle("/metrics", promhttp.Handler()) + // Add most trivial healthcheck + http.HandleFunc("/health", healthHandler) log.Fatal(http.ListenAndServe(statsPort, nil)) }() return &Stats{}