Skip to content

Commit

Permalink
pass server ID to health check method for re-usability
Browse files Browse the repository at this point in the history
  • Loading branch information
Roxana Meixner committed May 14, 2021
1 parent f035932 commit 57f2565
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions main/adapters/httphelper/resp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package httphelper

import (
"fmt"
"net/http"

log "github.com/sirupsen/logrus"
Expand All @@ -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)))
Expand Down
7 changes: 4 additions & 3 deletions main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -62,6 +62,7 @@ func main() {
configDir string
migrate bool
initIdentities bool
serverID = fmt.Sprintf("ubirch-client/%s", Version)
)

if len(os.Args) > 1 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 57f2565

Please sign in to comment.