// Command healthcheck checks the existing gRPC Health service for container readiness. package main import ( "context" "fmt" "os" "time" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/health/grpc_health_v1" ) func main() { if err := check(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func check() error { conn, err := grpc.NewClient("127.0.0.1:50112", grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return err } defer conn.Close() ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) defer cancel() result, err := grpc_health_v1.NewHealthClient(conn).Check(ctx, &grpc_health_v1.HealthCheckRequest{}) if err != nil { return err } if result.Status != grpc_health_v1.HealthCheckResponse_SERVING { return fmt.Errorf("gRPC service is %s", result.Status) } return nil }