How to Use context.Background and context.TODO

Use context.Background() for top-level contexts and context.TODO() as a temporary placeholder when the correct context is unknown.

Use context.Background() to start a new context at the top of your program, and context.TODO() as a placeholder when you don't yet know which context to use.

// Start at the top level
ctx := context.Background()

// Placeholder for later implementation
func handler(ctx context.Context) {
    // TODO: replace with proper context
    _ = context.TODO()
}