Skip to content

Commit c67bc17

Browse files
committed
Use unexported type for context keys
Make the ContextKey type unexported (contextKey) so no external package can construct a colliding key. The exported constants remain accessible across internal packages while the type itself is hidden.
1 parent cceb45a commit c67bc17

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

‎internal/common/ctxkeys/ctxkeys.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// collisions with plain string keys.
33
package ctxkeys
44

5-
// ContextKey is a typed key for context values, preventing collisions with
6-
// string keys from other packages.
7-
type ContextKey string
5+
// contextKey is an unexported type for context value keys, preventing any
6+
// external package from constructing a colliding key.
7+
type contextKey string
88

99
const (
1010
// PrincipalKey stores the authenticated Principal in a context.
11-
PrincipalKey ContextKey = "principal"
11+
PrincipalKey contextKey = "principal"
1212
// UserKey stores the authenticated username in a context for logging.
13-
UserKey ContextKey = "user"
13+
UserKey contextKey = "user"
1414
// RequestIDKey stores the request ID in a context for logging.
15-
RequestIDKey ContextKey = "requestId"
15+
RequestIDKey contextKey = "requestId"
1616
)

0 commit comments

Comments
 (0)