Skip to content

enable SA1029 to find inappropriate key in call to context.WithValue #40796

Closed
@hawkingrei

Description

Enhancement

Staticcheck has many check items. but we don't enable everyone. so we need to enable SA1029 to find inappropriate key in call to context.WithValue.

The provided key must be comparable and should not be of type string or any other built-in type to avoid collisions between packages using context. Users of WithValue should define their own types for keys.

To avoid allocating when assigning to an interface{}, context keys often have concrete type struct{}. Alternatively, exported context key variables’ static type should be a pointer or interface.

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions