package main import ( "context" "fmt" "io" "log" "github.com/go-kratos/kratos/v2/middleware/recovery" transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" pb "google.golang.org/grpc/health/grpc_health_v1" ) func main() { conn, err := transgrpc.DialInsecure( context.Background(), transgrpc.WithEndpoint("127.0.0.1:9010"), transgrpc.WithMiddleware( recovery.Recovery(), ), ) if err != nil { panic(err) } defer conn.Close() client := pb.NewHealthClient(conn) stream, err := client.Watch(context.Background(), &pb.HealthCheckRequest{Service: "health"}) if err != nil { log.Fatal(err) } for { res, err := stream.Recv() if err == io.EOF { fmt.Println("EOF") break } if err != nil { log.Fatalf("ListStr get stream err: %v", err) } // 打印返回值 log.Println(res.Status) } }