Created
March 4, 2022 11:11
-
-
Save ankur22/8ead554d5c966e8af536456c0077a24a to your computer and use it in GitHub Desktop.
Checking whether the underlying client and context have a context and setting one on the context if no timeout set in either
This file contains 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
// Set a timeout of 10secs if no timeout in the underlying | |
// http client and no timeout set in the context. | |
_, ok := ctx.Deadline() | |
if c.c.Timeout == 0 && !ok { | |
var cancel context.CancelFunc | |
ctx, cancel = context.WithTimeout(ctx, time.Second*10) | |
defer cancel() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment