Skip to content

Commit dfb249d

Browse files
committed
refactor: replace contextKey with authKey for improved type safety in context operations
Signed-off-by: tbxark <tbxark@outlook.com>
1 parent 0b22ff8 commit dfb249d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

server/auth/authorizer/context.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
)
66

7-
type contextKey string
7+
type authKey struct{}
88

9-
const contextKeyAuthorizerID = contextKey("authorizer")
9+
var authContextKey = authKey{}
1010

1111
type Data[I UID] struct {
1212
UID I `json:"uid"`
@@ -15,11 +15,11 @@ type Data[I UID] struct {
1515
}
1616

1717
func WithAuthData[I UID](ctx context.Context, data Data[I]) context.Context {
18-
return context.WithValue(ctx, contextKeyAuthorizerID, data)
18+
return context.WithValue(ctx, authContextKey, data)
1919
}
2020

2121
func GetAuthData[I UID](ctx context.Context) (Data[I], bool) {
22-
raw := ctx.Value(contextKeyAuthorizerID)
22+
raw := ctx.Value(authContextKey)
2323
if raw == nil {
2424
return Data[I]{}, false
2525
}

0 commit comments

Comments
 (0)