Public source validation / validate (push) Failing after 3m8s
26 lines
701 B
Go
26 lines
701 B
Go
package service
|
|
|
|
import "net/http"
|
|
|
|
func HealthMux() *http.ServeMux {
|
|
return HealthMuxWithReadiness(func() bool { return true })
|
|
}
|
|
|
|
func HealthMuxWithReadiness(ready func() bool) *http.ServeMux {
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/healthz", func(response http.ResponseWriter, _ *http.Request) {
|
|
response.WriteHeader(http.StatusOK)
|
|
_, _ = response.Write([]byte("ok\n"))
|
|
})
|
|
mux.HandleFunc("/readyz", func(response http.ResponseWriter, _ *http.Request) {
|
|
if !ready() {
|
|
response.WriteHeader(http.StatusServiceUnavailable)
|
|
_, _ = response.Write([]byte("not ready\n"))
|
|
return
|
|
}
|
|
response.WriteHeader(http.StatusOK)
|
|
_, _ = response.Write([]byte("ready\n"))
|
|
})
|
|
return mux
|
|
}
|