Files
ucan/toolkit/server/context.go

28 lines
790 B
Go
Raw Normal View History

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