From 6f4853cd2f1f4fd13f44f9dbc82f07e9459bbce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 27 Nov 2024 12:23:56 +0100 Subject: [PATCH] bearer,context: support hash verification of the computed args --- toolkit/server/context.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/toolkit/server/context.go b/toolkit/server/context.go index 83fe096..701d203 100644 --- a/toolkit/server/context.go +++ b/toolkit/server/context.go @@ -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) }