Standard library / context
context.Context
Interface for deadlines, cancellation signals, errors and request-scoped values. Its methods may be used concurrently. Expected stdout: 'false true true true\n'.
Formal Syntax & Structure
go syntaxgo
type Context interface { Deadline() (deadline time.Time, ok bool)
Done() <-chan struct{}
Err() error
Value(key any) any}Working Example
Example Snippetgo
package main
import ( "context" "fmt")
func main() { var ctx context.Context = context.Background() _, ok := ctx.Deadline() fmt.Println(ok, ctx.Done() == nil, ctx.Err() == nil, ctx.Value(struct{}{}) == nil)}