This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user