Go context

A context carries request-scoped values, cancellation signals, and deadlines across API boundaries. In Go services, contexts let handlers and downstream operations stop work when a request is cancelled or its deadline expires.

Minimal example

go
func handle(ctx context.Context) error {
    select {
    case <-ctx.Done():
        return ctx.Err()
    default:
        return nil
    }
}

Learn this concept

Lesson 1.17 · The chi router and context.Context

Used in exercises

Exercise 1.19 · chi server with /healthz and a rate limit Exercise 1.22 · Redis fixed-window limiter that fails open Exercise 1.29 · Optional: Token bucket in Redis with Lua and EVALSHA Exercise 5.5 · Per-user order event bridge Exercise 5.7 · Rider presence service Exercise 5.15 · Per-user Redis replay log Exercise 6.2 · Menu cache and stock updater Exercise 7.17 · gRPC resilience interceptors
Prerequisite conceptsGo functionsHTTP handler