Merge b9d6964b7e2bc3e12e1d06443073d7a114073b3e into 5f4f9643258dc2a65e684b63f12c8d543c936c67

This commit is contained in:
Kasidej 2026-05-15 04:08:43 +08:00 committed by GitHub
commit fd57313953
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -1477,11 +1477,9 @@ 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
} }

View File

@ -2931,6 +2931,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) {