forked from hidevopsio/hiboot
/
health.go
39 lines (33 loc) · 925 Bytes
/
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
37
38
39
package grpc
import (
"context"
pb "google.golang.org/grpc/health/grpc_health_v1"
"hidevops.io/hiboot/pkg/at"
"time"
)
// controller
type HealthCheckService struct {
at.HealthCheckService
// declare HelloServiceClient
healthClient pb.HealthClient
}
// NewHealthCheckService is the constructor of healthCheckService
func NewHealthCheckService(healthClient pb.HealthClient) *HealthCheckService {
return &HealthCheckService{
healthClient: healthClient,
}
}
// Status return health check display name grpc
func (c *HealthCheckService) Name() (name string) {
return Profile
}
// Status return grpc health check status as bool
func (c *HealthCheckService) Status() (up bool) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
resp, err := c.healthClient.Check(ctx, &pb.HealthCheckRequest{})
if err == nil {
up = resp.Status == pb.HealthCheckResponse_SERVING
}
return
}