From 57f25652bc4a2b22faa81830c07613d9fa53340e Mon Sep 17 00:00:00 2001 From: Roxana Meixner Date: Fri, 14 May 2021 16:23:54 +0200 Subject: [PATCH] pass server ID to health check method for re-usability --- main/adapters/httphelper/resp.go | 5 ++--- main/main.go | 7 ++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main/adapters/httphelper/resp.go b/main/adapters/httphelper/resp.go index 8bfb3c10..f4a6fe38 100644 --- a/main/adapters/httphelper/resp.go +++ b/main/adapters/httphelper/resp.go @@ -1,7 +1,6 @@ package httphelper import ( - "fmt" "net/http" log "github.com/sirupsen/logrus" @@ -13,9 +12,9 @@ type HTTPResponse struct { Content []byte `json:"content"` } -func Health(version string) http.HandlerFunc { +func Health(server string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Server", fmt.Sprintf("ubirch-go-client/%s", version)) + w.Header().Set("Server", server) w.Header().Set(HeaderContentType, MimeTextPlain) w.WriteHeader(http.StatusOK) _, err := w.Write([]byte(http.StatusText(http.StatusOK))) diff --git a/main/main.go b/main/main.go index a98dd023..43046d08 100644 --- a/main/main.go +++ b/main/main.go @@ -42,7 +42,7 @@ func shutdown(cancel context.CancelFunc) { // block until we receive a SIGINT or SIGTERM sig := <-signals - log.Printf("shutting down after receiving: %v", sig) + log.Infof("shutting down after receiving: %v", sig) // cancel the go routines contexts cancel() @@ -62,6 +62,7 @@ func main() { configDir string migrate bool initIdentities bool + serverID = fmt.Sprintf("ubirch-client/%s", Version) ) if len(os.Args) > 1 { @@ -124,7 +125,7 @@ func main() { p.InitPromMetrics(httpServer.Router) // set up endpoint for liveliness checks - httpServer.Router.Get("/healtz", h.Health(globals.Version)) + httpServer.Router.Get("/healtz", h.Health(serverID)) if migrate { err := repository.Migrate(conf) @@ -207,7 +208,7 @@ func main() { }) // set up endpoint for readiness checks - httpServer.Router.Get("/readiness", h.Health(globals.Version)) + httpServer.Router.Get("/readiness", h.Health(serverID)) log.Info("ready") // wait for all go routines of the waitgroup to return