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

Function main

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

Source from the content-addressed store, hash-verified

36var addr = flag.String("addr", "localhost:50051", "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 conn.Close()
47
48 c := pb.NewEchoClient(conn)
49
50 // Send the RPC compressed. If all RPCs on a client should be sent this
51 // way, use the DialOption:
52 // grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name))
53 const msg = "compress"
54 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
55 defer cancel()
56 res, err := c.UnaryEcho(ctx, &pb.EchoRequest{Message: msg}, grpc.UseCompressor(gzip.Name))
57 fmt.Printf("UnaryEcho call returned %q, %v\n", res.GetMessage(), err)
58 if err != nil || res.GetMessage() != msg {
59 log.Fatalf("Message=%q, err=%v; want Message=%q, err=<nil>", res.GetMessage(), err, msg)
60 }
61
62}

Callers

nothing calls this directly

Calls 10

UnaryEchoMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
UseCompressorFunction · 0.92
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
PrintfMethod · 0.65
GetMessageMethod · 0.45

Tested by

no test coverage detected