-
Notifications
You must be signed in to change notification settings - Fork 1
/
route_health.go
32 lines (27 loc) · 938 Bytes
/
route_health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package wess
import (
"net/http"
"github.com/gildas/go-core"
"github.com/gildas/go-logger"
"github.com/gorilla/mux"
)
// healthRoutes adds the Health Routes to the given Router
func (server *Server) healthRoutes(router *mux.Router) {
router.Methods("GET").Path("/liveness").Handler(healthHandler(server, "liveness"))
router.Methods("GET").Path("/readiness").Handler(healthHandler(server, "readiness"))
}
// healthHandler handles the readiness probe
func healthHandler(server *Server, probename string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log := logger.Must(logger.FromContext(r.Context())).Child("health", probename)
if !server.IsReady() {
log.Errorf("Webserver not ready yet")
w.WriteHeader(http.StatusServiceUnavailable)
return
}
if core.GetEnvAsBool("TRACE_PROBE", false) {
log.Infof("The application is ready")
}
w.WriteHeader(http.StatusOK)
})
}