Files
ucan/toolkit/server/context.go

29 lines
816 B
Go
Raw Normal View History

2024-09-18 12:10:08 +02:00
package server
import "context"
type contextKey string
var ctxUserId = contextKey("userId")
var ctxProjectId = contextKey("projectId")
// ContextGetUserId return the UserId stored in the context, if it exists.
func ContextGetUserId(ctx context.Context) (string, bool) {
val, ok := ctx.Value(ctxUserId).(string)
return val, ok
}
func addUserIdToContext(ctx context.Context, userId string) context.Context {
return context.WithValue(ctx, ctxUserId, userId)
}
// ContextGetProjectId return the ProjectID stored in the context, if it exists.
func ContextGetProjectId(ctx context.Context) (string, bool) {
val, ok := ctx.Value(ctxProjectId).(string)
return val, ok
}
func addProjectIdToContext(ctx context.Context, projectId string) context.Context {
return context.WithValue(ctx, ctxProjectId, projectId)
}