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

Function main

examples/features/authentication/client/main.go:49–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47}
48
49func main() {
50 flag.Parse()
51
52 // Set up the credentials for the connection.
53 perRPC := oauth.TokenSource{TokenSource: oauth2.StaticTokenSource(fetchToken())}
54 creds, err := credentials.NewClientTLSFromFile(data.Path("x509/ca_cert.pem"), "x.test.example.com")
55 if err != nil {
56 log.Fatalf("failed to load credentials: %v", err)
57 }
58 opts := []grpc.DialOption{
59 // In addition to the following grpc.DialOption, callers may also use
60 // the grpc.CallOption grpc.PerRPCCredentials with the RPC invocation
61 // itself.
62 // See: https://godoc.org/google.golang.org/grpc#PerRPCCredentials
63 grpc.WithPerRPCCredentials(perRPC),
64 // oauth.TokenSource requires the configuration of transport
65 // credentials.
66 grpc.WithTransportCredentials(creds),
67 }
68
69 conn, err := grpc.NewClient(*addr, opts...)
70 if err != nil {
71 log.Fatalf("did not connect: %v", err)
72 }
73 defer conn.Close()
74 rgc := ecpb.NewEchoClient(conn)
75
76 callUnaryEcho(rgc, "hello world")
77}
78
79// fetchToken simulates a token lookup and omits the details of proper token
80// acquisition. For examples of how to acquire an OAuth2 token, see:

Callers

nothing calls this directly

Calls 10

NewClientTLSFromFileFunction · 0.92
PathFunction · 0.92
WithPerRPCCredentialsFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewClientFunction · 0.92
fetchTokenFunction · 0.85
callUnaryEchoFunction · 0.70
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected