15 lines
288 B
Go
15 lines
288 B
Go
package httpx
|
|
|
|
import "context"
|
|
|
|
type userIDKey struct{}
|
|
|
|
func WithUserID(ctx context.Context, userID int64) context.Context {
|
|
return context.WithValue(ctx, userIDKey{}, userID)
|
|
}
|
|
|
|
func UserID(ctx context.Context) (int64, bool) {
|
|
v, ok := ctx.Value(userIDKey{}).(int64)
|
|
return v, ok
|
|
}
|