mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-10 16:47:05 +08:00
Compare commits
4 Commits
c473087bea
...
50893d9668
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50893d9668 | ||
|
|
578858229b | ||
|
|
2ef64e8946 | ||
|
|
c08ca6ebb3 |
@ -1436,10 +1436,8 @@ func (c *Context) Value(key any) any {
|
|||||||
if key == ContextKey {
|
if key == ContextKey {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
if keyAsString, ok := key.(string); ok {
|
if val, exists := c.Get(key); exists {
|
||||||
if val, exists := c.Get(keyAsString); exists {
|
return val
|
||||||
return val
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !c.hasRequestContext() {
|
if !c.hasRequestContext() {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -2859,6 +2859,10 @@ func TestContextGolangContext(t *testing.T) {
|
|||||||
c.Set("foo", "bar")
|
c.Set("foo", "bar")
|
||||||
assert.Equal(t, "bar", c.Value("foo"))
|
assert.Equal(t, "bar", c.Value("foo"))
|
||||||
assert.Nil(t, c.Value(1))
|
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) {
|
func TestWebsocketsRequired(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user