mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 09:12:28 +00:00
interceptors: add ban
health: set services serving on start and not available on close Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@ -56,6 +56,8 @@ type service struct {
|
||||
inproc *inprocgrpc.Channel
|
||||
services map[string]*serviceInfo
|
||||
|
||||
healthServer *health.Server
|
||||
|
||||
id string
|
||||
regSvc *registry.Service
|
||||
closed chan struct{}
|
||||
@ -120,7 +122,8 @@ func newService(opts ...Option) (*service, error) {
|
||||
greflect.Register(s.server)
|
||||
}
|
||||
if s.opts.health {
|
||||
s.registerService(&grpc_health_v1.Health_ServiceDesc, health.NewServer())
|
||||
s.healthServer = health.NewServer()
|
||||
s.registerService(&grpc_health_v1.Health_ServiceDesc, s.healthServer)
|
||||
}
|
||||
if err := s.gateway(s.opts.gatewayOpts...); err != nil {
|
||||
return nil, err
|
||||
@ -226,6 +229,18 @@ func (s *service) run() error {
|
||||
}
|
||||
errs <- nil
|
||||
}()
|
||||
if s.healthServer != nil {
|
||||
for k := range s.services {
|
||||
s.healthServer.SetServingStatus(k, grpc_health_v1.HealthCheckResponse_SERVING)
|
||||
}
|
||||
defer func() {
|
||||
if s.healthServer != nil {
|
||||
for k := range s.services {
|
||||
s.healthServer.SetServingStatus(k, grpc_health_v1.HealthCheckResponse_NOT_SERVING)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
for i := range s.opts.afterStart {
|
||||
if err := s.opts.afterStart[i](); err != nil {
|
||||
s.mu.Unlock()
|
||||
|
Reference in New Issue
Block a user