mirror of
https://github.com/go-kratos/kratos.git
synced 2025-11-06 08:59:18 +02:00
feat(transport/grpc): support custom healthcheck (#2541)
* feat(transport/grpc): support custom healthcheck * fix: parameters grpc server * fix(transport/grpc): optional CustomHealth * fix(transport/grpc): useless argument
This commit is contained in:
@@ -67,6 +67,13 @@ func Middleware(m ...middleware.Middleware) ServerOption {
|
||||
}
|
||||
}
|
||||
|
||||
// CustomHealth Checks server.
|
||||
func CustomHealth() ServerOption {
|
||||
return func(s *Server) {
|
||||
s.customHealth = true
|
||||
}
|
||||
}
|
||||
|
||||
// TLSConfig with TLS config.
|
||||
func TLSConfig(c *tls.Config) ServerOption {
|
||||
return func(s *Server) {
|
||||
@@ -105,20 +112,21 @@ func Options(opts ...grpc.ServerOption) ServerOption {
|
||||
// Server is a gRPC server wrapper.
|
||||
type Server struct {
|
||||
*grpc.Server
|
||||
baseCtx context.Context
|
||||
tlsConf *tls.Config
|
||||
lis net.Listener
|
||||
err error
|
||||
network string
|
||||
address string
|
||||
endpoint *url.URL
|
||||
timeout time.Duration
|
||||
middleware matcher.Matcher
|
||||
unaryInts []grpc.UnaryServerInterceptor
|
||||
streamInts []grpc.StreamServerInterceptor
|
||||
grpcOpts []grpc.ServerOption
|
||||
health *health.Server
|
||||
metadata *apimd.Server
|
||||
baseCtx context.Context
|
||||
tlsConf *tls.Config
|
||||
lis net.Listener
|
||||
err error
|
||||
network string
|
||||
address string
|
||||
endpoint *url.URL
|
||||
timeout time.Duration
|
||||
middleware matcher.Matcher
|
||||
unaryInts []grpc.UnaryServerInterceptor
|
||||
streamInts []grpc.StreamServerInterceptor
|
||||
grpcOpts []grpc.ServerOption
|
||||
health *health.Server
|
||||
customHealth bool
|
||||
metadata *apimd.Server
|
||||
}
|
||||
|
||||
// NewServer creates a gRPC server by options.
|
||||
@@ -159,7 +167,9 @@ func NewServer(opts ...ServerOption) *Server {
|
||||
srv.Server = grpc.NewServer(grpcOpts...)
|
||||
srv.metadata = apimd.NewServer(srv.Server)
|
||||
// internal register
|
||||
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health)
|
||||
if !srv.customHealth {
|
||||
grpc_health_v1.RegisterHealthServer(srv.Server, srv.health)
|
||||
}
|
||||
apimd.RegisterMetadataServer(srv.Server, srv.metadata)
|
||||
reflection.Register(srv.Server)
|
||||
return srv
|
||||
|
||||
Reference in New Issue
Block a user