Files
pedestrian-simulator/server/context.go

19 lines
450 B
Go
Raw Normal View History

2026-01-11 17:16:59 -07:00
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
}