()
| 47 | } |
| 48 | |
| 49 | func 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: |
nothing calls this directly
no test coverage detected