diff --git a/health/grpc_health_v1alpha/health.proto b/health/grpc_health_v1alpha/health.proto index 07615ba5..747a4f03 100644 --- a/health/grpc_health_v1alpha/health.proto +++ b/health/grpc_health_v1alpha/health.proto @@ -9,7 +9,7 @@ message HealthCheckRequest { message HealthCheckResponse { enum ServingStatus { - UNKNOWN = 0; + UNKNOWN = 0; SERVING = 1; NOT_SERVING = 2; } diff --git a/health/health.go b/health/health.go index 7670acb7..3f689fed 100644 --- a/health/health.go +++ b/health/health.go @@ -12,9 +12,9 @@ import ( ) type HealthServer struct { - // statusMap stores the serving status of the services this HealthServer monitors + mu sync.Mutex + // statusMap stores the serving status of the services this HealthServer monitors. statusMap map[string]int32 - mu sync.Mutex } func NewHealthServer() *HealthServer { @@ -23,9 +23,8 @@ func NewHealthServer() *HealthServer { } } -func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (out *healthpb.HealthCheckResponse, err error) { +func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*healthpb.HealthCheckResponse, error) { service := in.Host + ":" + in.Service - out = new(healthpb.HealthCheckResponse) s.mu.Lock() defer s.mu.Unlock() if status, ok := s.statusMap[service]; ok { @@ -37,7 +36,7 @@ func (s *HealthServer) Check(ctx context.Context, in *healthpb.HealthCheckReques } // SetServingStatus is called when need to reset the serving status of a service -// or insert a new service entry into the statusMap +// or insert a new service entry into the statusMap. func (s *HealthServer) SetServingStatus(host string, service string, status int32) { service = host + ":" + service s.mu.Lock()