Canonical guidance

Use when

Avoid

Preferred pattern

type requestIDKey struct{}

func WithRequestID(ctx context.Context, id string) context.Context {
	return context.WithValue(ctx, requestIDKey{}, id)
}

Anti-pattern

Explanation: This anti-pattern is tempting because it avoids changing signatures, but it destroys API clarity and type safety.

Why

Related pages

Sources