blob: b8987e48ab6977ad9ad708d00fe267d2d7ada2b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package context
import (
"context"
)
type contextKey string
const userIDContextKey contextKey = "user_id"
// SetUserID adds the user ID to the context
func SetUserID(ctx context.Context, userID int64) context.Context {
return context.WithValue(ctx, userIDContextKey, userID)
}
// GetUserID retrieves the user ID from the request context
func GetUserID(ctx context.Context) (int64, bool) {
userID, ok := ctx.Value(userIDContextKey).(int64)
return userID, ok
}
|