mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-13 18:00:00 +08:00
add custom health response information (#4034)
Co-authored-by: Kevin Wan <wanjunfeng@gmail.com>
This commit is contained in:
@@ -44,10 +44,10 @@ func AddProbe(probe Probe) {
|
||||
}
|
||||
|
||||
// CreateHttpHandler create health http handler base on given probe.
|
||||
func CreateHttpHandler() http.HandlerFunc {
|
||||
func CreateHttpHandler(healthRespInfo string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, _ *http.Request) {
|
||||
if defaultHealthManager.IsReady() {
|
||||
_, _ = w.Write([]byte("OK"))
|
||||
_, _ = w.Write([]byte(healthRespInfo))
|
||||
} else {
|
||||
http.Error(w, "Service Unavailable\n"+defaultHealthManager.verboseInfo(),
|
||||
http.StatusServiceUnavailable)
|
||||
|
||||
@@ -121,7 +121,7 @@ func TestAddGlobalProbes(t *testing.T) {
|
||||
|
||||
func TestCreateHttpHandler(t *testing.T) {
|
||||
cleanupForTest(t)
|
||||
srv := httptest.NewServer(CreateHttpHandler())
|
||||
srv := httptest.NewServer(CreateHttpHandler("OK"))
|
||||
defer srv.Close()
|
||||
|
||||
resp, err := http.Get(srv.URL)
|
||||
|
||||
Reference in New Issue
Block a user