Skip to content

Commit

Permalink
internal: split proto package import in health package (#2442)
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl authored Nov 6, 2018
1 parent d27440d commit c94cef3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions health/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"golang.org/x/net/context"
"google.golang.org/grpc/codes"
healthgrpc "google.golang.org/grpc/health/grpc_health_v1"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/status"
)
Expand All @@ -36,14 +37,14 @@ type Server struct {
mu sync.Mutex
// statusMap stores the serving status of the services this Server monitors.
statusMap map[string]healthpb.HealthCheckResponse_ServingStatus
updates map[string]map[healthpb.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus
updates map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus
}

// NewServer returns a new Server.
func NewServer() *Server {
return &Server{
statusMap: map[string]healthpb.HealthCheckResponse_ServingStatus{"": healthpb.HealthCheckResponse_SERVING},
updates: make(map[string]map[healthpb.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus),
updates: make(map[string]map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus),
}
}

Expand All @@ -60,7 +61,7 @@ func (s *Server) Check(ctx context.Context, in *healthpb.HealthCheckRequest) (*h
}

// Watch implements `service Health`.
func (s *Server) Watch(in *healthpb.HealthCheckRequest, stream healthpb.Health_WatchServer) error {
func (s *Server) Watch(in *healthpb.HealthCheckRequest, stream healthgrpc.Health_WatchServer) error {
service := in.Service
// update channel is used for getting service status updates.
update := make(chan healthpb.HealthCheckResponse_ServingStatus, 1)
Expand All @@ -74,7 +75,7 @@ func (s *Server) Watch(in *healthpb.HealthCheckRequest, stream healthpb.Health_W

// Registers the update channel to the correct place in the updates map.
if _, ok := s.updates[service]; !ok {
s.updates[service] = make(map[healthpb.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus)
s.updates[service] = make(map[healthgrpc.Health_WatchServer]chan healthpb.HealthCheckResponse_ServingStatus)
}
s.updates[service][stream] = update
defer func() {
Expand Down
4 changes: 2 additions & 2 deletions health/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/health"
pb "google.golang.org/grpc/health/grpc_health_v1"
healthgrpc "google.golang.org/grpc/health/grpc_health_v1"
)

// Make sure the service implementation complies with the proto definition.
func TestRegister(t *testing.T) {
s := grpc.NewServer()
pb.RegisterHealthServer(s, health.NewServer())
healthgrpc.RegisterHealthServer(s, health.NewServer())
s.Stop()
}

0 comments on commit c94cef3

Please sign in to comment.