-- 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)
| 270 | // credentials.TransportCredentials object. Once we have that, actually making |
| 271 | // the calls with gRPC is the same. |
| 272 | func 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 | } |
| 294 | func main() { |
| 295 | credsDirectory := flag.String("credentials_directory", "", "Path to the creds directory of this example repo") |
| 296 | flag.Parse() |
no test coverage detected