In Go, a context is the main device to propagate deadlines and scoped values across APIs. Use this tag for questions related to context.Context type in Go, or third-party types that implement the Context interface.
Context is the preferred way in Go to carry request-scoped information across API boundaries, and between processes.
The package documentation recommends three main best practices when using context.Context
, which are repeated here:
- Context arguments should be passed as the first argument to functions that need it. This way is preferred to declaring context fields inside structs
context.TODO
is to be used in place of anil
context- Context values should be used only for request-scoped values, and not to pass optional parameters to functions.