2017-07-24 07:06:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-14 06:18:48 +00:00
|
|
|
"context"
|
2017-07-24 07:06:23 +00:00
|
|
|
"log"
|
2017-11-14 06:18:48 +00:00
|
|
|
"time"
|
2017-07-24 07:06:23 +00:00
|
|
|
|
2017-11-14 06:18:48 +00:00
|
|
|
"github.com/appleboy/gorush/rpc"
|
2017-11-12 14:44:33 +00:00
|
|
|
|
2017-07-24 07:06:23 +00:00
|
|
|
"google.golang.org/grpc"
|
2021-08-03 06:44:00 +00:00
|
|
|
"google.golang.org/grpc/status"
|
2017-07-24 07:06:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2017-10-19 01:24:47 +00:00
|
|
|
address = "localhost:9000"
|
2017-07-24 07:06:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
// Set up a connection to the server.
|
|
|
|
conn, err := grpc.Dial(address, grpc.WithInsecure())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("did not connect: %v", err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
|
2017-11-14 06:18:48 +00:00
|
|
|
client := rpc.NewGrpcHealthClient(conn)
|
|
|
|
|
|
|
|
for {
|
|
|
|
ok, err := client.Check(context.Background())
|
|
|
|
if !ok || err != nil {
|
2021-08-03 06:44:00 +00:00
|
|
|
log.Printf("can't connect grpc server: %v, code: %v\n", err, status.Code(err))
|
2017-11-14 06:18:48 +00:00
|
|
|
} else {
|
|
|
|
log.Println("connect the grpc server successfully")
|
|
|
|
}
|
|
|
|
|
|
|
|
<-time.After(time.Second)
|
2017-07-24 07:06:23 +00:00
|
|
|
}
|
|
|
|
}
|