Documentation
¶
Overview ¶
Package ctxutil provides utility functions for storing and retrieving request-scoped values in context.Context.
Index ¶
- Variables
- func Actor(ctx context.Context) (string, bool)
- func CausationID(ctx context.Context) (uuid.UUID, bool)
- func CorrelationID(ctx context.Context) (string, bool)
- func Permissions(ctx context.Context) ([]string, bool)
- func RequestID(ctx context.Context) (string, bool)
- func ResolveActor(ctx context.Context) (string, error)
- func Roles(ctx context.Context) ([]string, bool)
- func TenantID(ctx context.Context) (string, bool)
- func UserID(ctx context.Context) (string, bool)
- func WithActor(ctx context.Context, actor string) context.Context
- func WithCausationID(ctx context.Context, eventID uuid.UUID) context.Context
- func WithClaims(ctx context.Context, claims Claims) context.Context
- func WithCorrelationID(ctx context.Context, id string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- func WithTenantID(ctx context.Context, id string) context.Context
- type Claims
Constants ¶
This section is empty.
Variables ¶
var ErrNoActor = errors.New("ctxutil: no actor in context")
ErrNoActor reports a context that has neither an Actor nor a Claims.UserID outside the reserved "system:" prefix.
Functions ¶
func Actor ¶ added in v0.8.0
Actor returns the actor set by WithActor. Claims are not consulted. An empty value counts as absent.
func CausationID ¶ added in v0.8.0
CausationID returns the causation EventID set by WithCausationID. uuid.Nil counts as absent.
func CorrelationID ¶ added in v0.8.0
CorrelationID returns the correlation ID set by WithCorrelationID. The request ID is not consulted. An empty value counts as absent.
func Permissions ¶
Permissions returns the permissions from the context claims.
func ResolveActor ¶ added in v0.8.0
ResolveActor returns the Actor set by WithActor, falling back to Claims.UserID. It returns ErrNoActor when both are empty, or when the user ID carries the reserved "system:" prefix, so users cannot pose as library components.
func TenantID ¶
TenantID returns the tenant ID set by WithTenantID, falling back to Claims.TenantID. Empty values count as absent.
func WithActor ¶ added in v0.8.0
WithActor returns a new context with the actor set: the user or component (system:<component>:<name>) on whose behalf work runs.
func WithCausationID ¶ added in v0.8.0
WithCausationID returns a new context with the causation ID set: the EventID of the event that caused the work running in this context.
func WithClaims ¶
WithClaims returns a new context with the claims set.
func WithCorrelationID ¶ added in v0.8.0
WithCorrelationID returns a new context with the correlation ID set, shared by everything one request, scheduled run or inbox message caused.
func WithRequestID ¶
WithRequestID returns a new context with the request ID set.