context

The Go standard library package whose Context value carries a deadline, a cancellation signal and request-scoped values through a chain of function calls.

In more detail

By convention a Context is the first parameter, named ctx. context.Background() is the empty root that others are derived from. Functions watch ctx.Done() and stop with ctx.Err() when it closes. Keep ordinary configuration in parameters, not in context values.

Example

func report(ctx context.Context) {}

Related terms

Taught in

References