Documentation
¶
Overview ¶
Package ctxv provides type-safe context values through generic keys, eliminating the boilerplate of type assertions with context.Value. It has zero external dependencies.
Key[T] is a zero-value generic key type. NewKey creates a unique key bound to type T, and WithValue/Value/MustValue provide the standard context read-write operations with compile-time type safety.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Key ¶
type Key[T any] struct { // contains filtered or unexported fields }
Key is a typed context key that stores values of type T. Each call to NewKey produces a unique key, even for the same type parameter. The zero value is not usable; construct with NewKey.
func (*Key[T]) MustValue ¶
MustValue retrieves a typed value from the context. Panics if the value is not found. This follows the Go Must convention (e.g. template.Must, regexp.MustCompile) where panic signals a programming error by the caller.