feat: add dev server and health (#2665)

* feat: add dev server and health

* fix: fix ci

* fix: fix comment.

* feat: add enabled

* remove no need test

* feat: mv devServer to internal

* feat: default enable pprof

Co-authored-by: dylan.wang <dylan.wang@yijinin.com>
This commit is contained in:
re-dylan
2022-12-10 20:40:23 +08:00
committed by GitHub
parent 944193ce25
commit ef22042f4d
9 changed files with 409 additions and 4 deletions

View File

@@ -7,8 +7,11 @@ import (
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/proc"
"github.com/zeromicro/go-zero/internal/health"
)
const probeNamePrefix = "rest"
// StartOption defines the method to customize http.Server.
type StartOption func(svr *http.Server)
@@ -37,8 +40,10 @@ func start(host string, port int, handler http.Handler, run func(svr *http.Serve
for _, opt := range opts {
opt(server)
}
healthManager := health.NewHealthManager(fmt.Sprintf("%s-%s:%d", probeNamePrefix, host, port))
waitForCalled := proc.AddWrapUpListener(func() {
healthManager.MarkNotReady()
if e := server.Shutdown(context.Background()); e != nil {
logx.Error(e)
}
@@ -49,5 +54,7 @@ func start(host string, port int, handler http.Handler, run func(svr *http.Serve
}
}()
healthManager.MarkReady()
health.AddProbe(healthManager)
return run(server)
}