fix: use typed context key instead of string literal- Add UserContextKey constant to types package- Replace bare string 'user' with types.UserContextKey in auth middleware- Update user service to use UserContextKey for context value retrieval- Fixes staticcheck SA1029 warningThis prevents potential context key collisions.

This commit is contained in:
DJ
2026-01-21 16:11:54 +08:00
committed by lyingbug
parent aa4af5365e
commit 8b160bba15
3 changed files with 5 additions and 3 deletions
+2 -2
View File
@@ -130,14 +130,14 @@ func Auth(
// 存储用户和租户信息到上下文
c.Set(types.TenantIDContextKey.String(), targetTenantID)
c.Set(types.TenantInfoContextKey.String(), tenant)
c.Set("user", user)
c.Set(types.UserContextKey.String(), user)
c.Request = c.Request.WithContext(
context.WithValue(
context.WithValue(
context.WithValue(c.Request.Context(), types.TenantIDContextKey, targetTenantID),
types.TenantInfoContextKey, tenant,
),
"user", user,
types.UserContextKey, user,
),
)
c.Next()