Skip to content

context-stored-in-struct

Detect context.Context fields in structs.

Updated View as Markdown

Default severity: warning

Contexts carry request-scoped cancellation, deadlines, and values. Keeping one in a struct obscures its lifetime and can accidentally reuse stale request state. Pass the context explicitly to each operation that needs it.

Bad

type Service struct { ctx context.Context }

Good

func (service *Service) Run(ctx context.Context) error
Navigation

Type to search…

↑↓ navigate↵ selectEsc close