Created
June 25, 2020 21:52
-
-
Save RicardoLinck/1167f15cf3993f485b67d8aca70ff149 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func greetWithTimeout(c greetpb.GreetServiceClient) { | |
req := &greetpb.GreetRequest{ | |
Greeting: &greetpb.Greeting{ | |
FirstName: "Ricardo", | |
LastName: "Linck", | |
}, | |
} | |
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) | |
defer cancel() | |
res, err := c.Greet(ctx, req) | |
if err != nil { | |
grpcErr, ok := status.FromError(err) | |
if ok { | |
if grpcErr.Code() == codes.DeadlineExceeded { | |
log.Fatal("Deadline Exceeded") | |
} | |
} | |
log.Fatalf("Error calling Greet RPC: %v", err) | |
} | |
log.Printf("Response: %s\n", res.Result) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment