mirror of
https://github.com/gin-gonic/gin.git
synced 2026-04-29 23:23:18 +08:00
Merge b9d6964b7e2bc3e12e1d06443073d7a114073b3e into d3ffc9985281dcf4d3bef604cce4e662b1a327a6
This commit is contained in:
commit
8612613044
@ -1477,10 +1477,8 @@ func (c *Context) Value(key any) any {
|
||||
if key == ContextKey {
|
||||
return c
|
||||
}
|
||||
if keyAsString, ok := key.(string); ok {
|
||||
if val, exists := c.Get(keyAsString); exists {
|
||||
return val
|
||||
}
|
||||
if val, exists := c.Get(key); exists {
|
||||
return val
|
||||
}
|
||||
if !c.hasRequestContext() {
|
||||
return nil
|
||||
|
||||
@ -2931,6 +2931,10 @@ func TestContextGolangContext(t *testing.T) {
|
||||
c.Set("foo", "bar")
|
||||
assert.Equal(t, "bar", c.Value("foo"))
|
||||
assert.Nil(t, c.Value(1))
|
||||
|
||||
type contextKey struct{}
|
||||
c.Set(contextKey{}, "value")
|
||||
assert.Equal(t, "value", c.Value(contextKey{}))
|
||||
}
|
||||
|
||||
func TestWebsocketsRequired(t *testing.T) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user