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
pull/2546/head
Aurélien Perrier 2 years ago committed by GitHub
parent a82c82d49f
commit d779faf091
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      transport/grpc/server.go

@ -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

Loading…
Cancel
Save