mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-12 17:46:57 +08:00
Merge 578858229b5dcb8a09d19c075d19f5c736e51dc6 into 9914178584e42458ff7d23891463a880f58c9d86
This commit is contained in:
commit
50893d9668
@ -1436,10 +1436,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
|
||||
|
||||
@ -2859,6 +2859,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