From c08ca6ebb3263eec996954690709033804d38b43 Mon Sep 17 00:00:00 2001 From: Kasidej Date: Mon, 5 Jan 2026 10:18:56 +0700 Subject: [PATCH 1/3] fix(context): update context.Value method to properly support any key type --- context.go | 4 +--- context_test.go | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index c42459ff..ddc1550f 100644 --- a/context.go +++ b/context.go @@ -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 { + if val, exists := c.Get(keyAsString); exists { return val - } } if !c.hasRequestContext() { return nil diff --git a/context_test.go b/context_test.go index 3080015c..bbfb10f2 100644 --- a/context_test.go +++ b/context_test.go @@ -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) { From 2ef64e894682927f911deb37b140bce0f93c1813 Mon Sep 17 00:00:00 2001 From: Kasidej Date: Mon, 5 Jan 2026 10:42:58 +0700 Subject: [PATCH 2/3] Fix key retrieval in context.go --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index ddc1550f..8382c168 100644 --- a/context.go +++ b/context.go @@ -1436,7 +1436,7 @@ func (c *Context) Value(key any) any { if key == ContextKey { return c } - if val, exists := c.Get(keyAsString); exists { + if val, exists := c.Get(key); exists { return val } if !c.hasRequestContext() { From 578858229b5dcb8a09d19c075d19f5c736e51dc6 Mon Sep 17 00:00:00 2001 From: Kasidej Date: Mon, 5 Jan 2026 10:45:19 +0700 Subject: [PATCH 3/3] Fix indentation in context.go --- context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/context.go b/context.go index 8382c168..60b4712c 100644 --- a/context.go +++ b/context.go @@ -1437,7 +1437,7 @@ func (c *Context) Value(key any) any { return c } if val, exists := c.Get(key); exists { - return val + return val } if !c.hasRequestContext() { return nil