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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user