Merge 0d9e3d19aff81c1fc40fbaea901c99b08ff48ad7 into 52ecf029bd2e9b4d2652f96dd2b753f8bc6b6e95

This commit is contained in:
Cheikh Seck 2025-11-26 23:43:49 +08:00 committed by GitHub
commit 1169aeea33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -299,6 +299,18 @@ func (c *Context) Get(key any) (value any, exists bool) {
return
}
// GetAs returns the value for the given key, ie: (value, true).
// If the value does not exist it returns (nil, false)
func (c *Context) GetAs[T any](key string) (result T, exists bool) {
value, exists := c.Get(key)
if !exists {
return
}
result, exists = value.(T)
return
}
// MustGet returns the value for the given key if it exists, otherwise it panics.
func (c *Context) MustGet(key any) any {
if value, exists := c.Get(key); exists {