MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

examples/features/error_details/client/main.go:38–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36var addr = flag.String("addr", "localhost:50052", "the address to connect to")
37
38func main() {
39 flag.Parse()
40
41 // Set up a connection to the server.
42 conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
43 if err != nil {
44 log.Fatalf("did not connect: %v", err)
45 }
46 defer func() {
47 if e := conn.Close(); e != nil {
48 log.Printf("failed to close connection: %s", e)
49 }
50 }()
51 c := pb.NewGreeterClient(conn)
52
53 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
54 defer cancel()
55 r, err := c.SayHello(ctx, &pb.HelloRequest{Name: "world"})
56 if err != nil {
57 s := status.Convert(err)
58 for _, d := range s.Details() {
59 switch info := d.(type) {
60 case *epb.QuotaFailure:
61 log.Printf("Quota failure: %s", info)
62 default:
63 log.Printf("Unexpected type: %s", info)
64 }
65 }
66 os.Exit(1)
67 }
68 log.Printf("Greeting: %s", r.Message)
69}

Callers

nothing calls this directly

Calls 10

SayHelloMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
ConvertFunction · 0.92
DetailsMethod · 0.80
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected