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

Function main

examples/features/error_handling/client/main.go:38–70  ·  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 name := "unknown"
42 if u, err := user.Current(); err == nil && u.Username != "" {
43 name = u.Username
44 }
45
46 // Set up a connection to the server.
47 conn, err := grpc.NewClient(*addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
48 if err != nil {
49 log.Fatalf("Failed to connect: %v", err)
50 }
51 defer conn.Close()
52 c := pb.NewGreeterClient(conn)
53
54 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
55 defer cancel()
56
57 for _, reqName := range []string{"", name} {
58 log.Printf("Calling SayHello with Name:%q", reqName)
59 r, err := c.SayHello(ctx, &pb.HelloRequest{Name: reqName})
60 if err != nil {
61 if status.Code(err) != codes.InvalidArgument {
62 log.Printf("Received unexpected error: %v", err)
63 continue
64 }
65 log.Printf("Received error: %v", err)
66 continue
67 }
68 log.Printf("Received response: %s", r.Message)
69 }
70}

Callers

nothing calls this directly

Calls 9

SayHelloMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
CodeFunction · 0.92
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
PrintfMethod · 0.65

Tested by

no test coverage detected