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. 10
      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) {
@ -118,6 +125,7 @@ type Server struct {
streamInts []grpc.StreamServerInterceptor
grpcOpts []grpc.ServerOption
health *health.Server
customHealth bool
metadata *apimd.Server
}
@ -159,7 +167,9 @@ func NewServer(opts ...ServerOption) *Server {
srv.Server = grpc.NewServer(grpcOpts...)
srv.metadata = apimd.NewServer(srv.Server)
// internal register
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