bearer,context: support hash verification of the computed args
This commit is contained in:
committed by
Michael Muré
parent
4c25456583
commit
6f4853cd2f
@@ -2,27 +2,26 @@ package server
|
||||
|
||||
import "context"
|
||||
|
||||
type contextKey string
|
||||
|
||||
var ctxUserId = contextKey("userId")
|
||||
var ctxProjectId = contextKey("projectId")
|
||||
type ctxUserIdKey struct{}
|
||||
|
||||
// ContextGetUserId return the UserId stored in the context, if it exists.
|
||||
func ContextGetUserId(ctx context.Context) (string, bool) {
|
||||
val, ok := ctx.Value(ctxUserId).(string)
|
||||
val, ok := ctx.Value(ctxUserIdKey{}).(string)
|
||||
return val, ok
|
||||
}
|
||||
|
||||
func addUserIdToContext(ctx context.Context, userId string) context.Context {
|
||||
return context.WithValue(ctx, ctxUserId, userId)
|
||||
return context.WithValue(ctx, ctxUserIdKey{}, userId)
|
||||
}
|
||||
|
||||
type ctxProjectIdKey struct{}
|
||||
|
||||
// ContextGetProjectId return the ProjectID stored in the context, if it exists.
|
||||
func ContextGetProjectId(ctx context.Context) (string, bool) {
|
||||
val, ok := ctx.Value(ctxProjectId).(string)
|
||||
val, ok := ctx.Value(ctxProjectIdKey{}).(string)
|
||||
return val, ok
|
||||
}
|
||||
|
||||
func addProjectIdToContext(ctx context.Context, projectId string) context.Context {
|
||||
return context.WithValue(ctx, ctxProjectId, projectId)
|
||||
return context.WithValue(ctx, ctxProjectIdKey{}, projectId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user