Function Patterns

Context

Use context.Context as the first parameter for functions that perform I/O or can be cancelled.

Example:

1    func Run(ctx context.Context, cmd Command) (Result, error) {
2	select {
3		case <-ctx.Done():
4			return Result{}, ctx.Err()
5		default:
6			// Execute command
7	}
8}
Last modified: 27/10/2025 2022-2025 ©ainsley.dev, All rights reserved.