Merge 0d9e3d19aff81c1fc40fbaea901c99b08ff48ad7 into 8763f33c65f7df8be5b9fe7504ab7fcf20abb41d

This commit is contained in:
Cheikh Seck 2025-03-21 00:28:36 +08:00 committed by GitHub
commit a725009876
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -283,6 +283,18 @@ func (c *Context) Get(key string) (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 string) any {
if value, exists := c.Get(key); exists {