-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc_health.go
36 lines (29 loc) · 1.06 KB
/
grpc_health.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package connect
import (
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
)
// HealthCheckService handler for health check rpc
type HealthCheckService struct{}
// RegisterHealthCheckService init health check service
func RegisterHealthCheckService(registrar grpc.ServiceRegistrar, customHandler grpc_health_v1.HealthServer) {
if customHandler != nil {
grpc_health_v1.RegisterHealthServer(registrar, customHandler)
return
}
// use default handler
grpc_health_v1.RegisterHealthServer(registrar, HealthCheckService{})
}
// Check :nodoc:
func (s HealthCheckService) Check(_ context.Context, _ *grpc_health_v1.HealthCheckRequest) (*grpc_health_v1.HealthCheckResponse, error) {
return &grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
}, nil
}
// Watch :nodoc:
func (s HealthCheckService) Watch(_ *grpc_health_v1.HealthCheckRequest, server grpc_health_v1.Health_WatchServer) error {
return server.Send(&grpc_health_v1.HealthCheckResponse{
Status: grpc_health_v1.HealthCheckResponse_SERVING,
})
}