Documentation
¶
Overview ¶
Package ctx provides type-safe context key helpers for Echo handlers.
It wraps Echo's context Set/Get with generics to avoid type assertion boilerplate and provides pre-defined keys used across the framework.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( SubjectIDKey = NewKey[string]("subject_id") SubjectKey = NewKey[any]("subject") SessionKey = NewKey[any]("session") RequestIDKey = NewKey[string]("request_id") FlashKey = NewKey[any]("flash") TranslatorKey = NewKey[any]("i18n_translator") LocaleKey = NewKey[string]("i18n_locale") )
Pre-defined keys used across the framework.
Functions ¶
func Get ¶
Get retrieves a typed value from the Echo context.
A nil context returns (zero, false) rather than panicking. Components render outside a request in normal use — middleware.ErrorPages builds its page from a func(code int, message string) with no echo.Context to pass down, so the scaffold's error page calls @Layout(nil, ...) — and every accessor built on Get (GetFlash, GetSubject, GetSubjectID) would otherwise nil-dereference there, turning a styled 404 into a recovered panic and a 500.
func GetAs ¶
GetAs retrieves a value from the Echo context using an untyped key and asserts it to type T. It returns (zero, false) on missing or mismatched type, and on a nil context (see Get).
func MustGet ¶
MustGet retrieves a typed value from the Echo context or panics. Panicking is the contract; a nil context says so explicitly rather than surfacing as a bare nil dereference from inside Echo.