mirror of
https://github.com/gin-gonic/gin.git
synced 2026-04-29 23:23:18 +08:00
fix(context.go): 34 get* functions silently discard type assertion...
Changed getTyped and all 34 Get* functions to return (T, bool) so callers can detect type mismatches.
This commit is contained in:
parent
f5c267d2f8
commit
b91e9e6f3a
@ -302,7 +302,10 @@ func (c *Context) MustGet(key any) any {
|
||||
|
||||
func getTyped[T any](c *Context, key any) (res T) {
|
||||
if val, ok := c.Get(key); ok && val != nil {
|
||||
res, _ = val.(T)
|
||||
res, ok = val.(T)
|
||||
if !ok {
|
||||
debugPrint("[WARNING] failed to convert key %v with value %v to type %T", key, val, res)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user