Junior — Middle
How to initialize a standard context without a timeout in Go?
sobes.tech AI
Answer from AI
In Go, the function context.Background() is used to create a context without a timeout. It returns an empty, non-cancelable context that usually serves as the root for other contexts.
Example of initializing a standard context without a timeout:
import "context"
func main() {
ctx := context.Background()
// ctx can be passed to functions that require a context
}
If a cancelable context is needed without a timeout, you can use context.WithCancel(ctx), but for a simple "empty" context without time constraints — context.Background().