blob: fd7b32747ad3359f2e650a336c9f6e77c7525e81 (
plain)
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
|
package rubyserver
import (
"net"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
)
func ping(address string) error {
conn, err := grpc.Dial(
address,
grpc.WithInsecure(),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}),
)
if err != nil {
return err
}
defer conn.Close()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
client := healthpb.NewHealthClient(conn)
_, err = client.Check(ctx, &healthpb.HealthCheckRequest{})
return err
}
|