1 parent
c5d00dc9a9
commit
24ecddd034
18 files changed
+4506
-4
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import "context"
|
||||
|
||||
type contextKey string
|
||||
|
||||
const userIDKey contextKey = "userID"
|
||||
|
||||
// withUserID adds the user ID to the request context
|
||||
func withUserID(ctx context.Context, userID string) context.Context {
|
||||
return context.WithValue(ctx, userIDKey, userID)
|
||||
}
|
||||
|
||||
// getUserID extracts the user ID from the request context
|
||||
func getUserID(ctx context.Context) (string, bool) {
|
||||
userID, ok := ctx.Value(userIDKey).(string)
|
||||
return userID, ok
|
||||
}
|
||||
Reference in new issue
Block a user