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

Function runWithCredentials

examples/features/advancedtls/client/main.go:272–293  ·  view source on GitHub ↗

-- Main and Runner -- All of these examples differ in how they configure the credentials.TransportCredentials object. Once we have that, actually making the calls with gRPC is the same.

(creds credentials.TransportCredentials, fullServerAddr string, shouldSucceed bool)

Source from the content-addressed store, hash-verified

270// credentials.TransportCredentials object. Once we have that, actually making
271// the calls with gRPC is the same.
272func runWithCredentials(creds credentials.TransportCredentials, fullServerAddr string, shouldSucceed bool) {
273 conn, err := grpc.NewClient(fullServerAddr, grpc.WithTransportCredentials(creds))
274 if err != nil {
275 fmt.Printf("Error during grpc.NewClient %v\n", err)
276 os.Exit(1)
277 }
278 defer conn.Close()
279 client := pb.NewEchoClient(conn)
280 req := &pb.EchoRequest{
281 Message: message,
282 }
283 context, cancel := context.WithTimeout(context.Background(), 10*time.Second)
284 resp, err := client.UnaryEcho(context, req)
285 defer cancel()
286
287 if shouldSucceed && err != nil {
288 fmt.Printf("Error during client.UnaryEcho %v\n", err)
289 } else if !shouldSucceed && err == nil {
290 fmt.Printf("Should have failed but didn't, got response: %v\n", resp)
291 }
292
293}
294func main() {
295 credsDirectory := flag.String("credentials_directory", "", "Path to the creds directory of this example repo")
296 flag.Parse()

Callers 4

runClientWithProvidersFunction · 0.85
credentialsNewTLSExampleFunction · 0.85

Calls 5

UnaryEchoMethod · 0.95
NewClientFunction · 0.92
WithTransportCredentialsFunction · 0.92
PrintfMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected