Documentation
¶
Overview ¶
Package xctx provides typed context helpers for request-scoped execution metadata. Context values are for cancellation, deadlines, and request metadata; application state should remain in explicit action parameters.
Index ¶
- Variables
- func AddTrace(ctx context.Context, event string)
- func ClientIPFrom(ctx context.Context) string
- func CloneForAsync(ctx context.Context) context.Context
- func EndpointFrom(ctx context.Context) string
- func FeaturesFrom(ctx context.Context) []string
- func FromClaims(scope *RequestScope, claims map[string]any)
- func HasAnyRole(ctx context.Context, allowed ...string) bool
- func HasFeature(ctx context.Context, feature string) bool
- func HasPermission(ctx context.Context, perm string) bool
- func HasRole(ctx context.Context, required string) bool
- func PermissionsFrom(ctx context.Context) []string
- func RequestIDFrom(ctx context.Context) string
- func TenantIDFrom(ctx context.Context) string
- func TraceIDFrom(ctx context.Context) string
- func UserIDFrom(ctx context.Context) string
- func WithClientIP(ctx context.Context, ip string) context.Context
- func WithEndpoint(ctx context.Context, endpoint string) context.Context
- func WithEventPublisher(ctx context.Context, pub EventPublisher) context.Context
- func WithFeatures(ctx context.Context, features []string) context.Context
- func WithPermissions(ctx context.Context, perms []string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- func WithRoles(ctx context.Context, roles []string) context.Context
- func WithScope(ctx context.Context, s *RequestScope) context.Context
- func WithTenantID(ctx context.Context, id string) context.Context
- func WithTraceID(ctx context.Context, id string) context.Context
- func WithUserID(ctx context.Context, id string) context.Context
- type EventPublisher
- type Key
- type RequestScope
Constants ¶
This section is empty.
Variables ¶
View Source
var TenantDB = NewKey[any]("tenant_db")
TenantDB is the context key for the active tenant's DB connection or transaction handle.
Functions ¶
func ClientIPFrom ¶
func EndpointFrom ¶
func FeaturesFrom ¶
func FromClaims ¶
func FromClaims(scope *RequestScope, claims map[string]any)
func PermissionsFrom ¶
func RequestIDFrom ¶
func TenantIDFrom ¶
func TraceIDFrom ¶
func UserIDFrom ¶
func WithEventPublisher ¶
func WithEventPublisher(ctx context.Context, pub EventPublisher) context.Context
WithEventPublisher injects an event bus or outbox publisher into the context.
Types ¶
type EventPublisher ¶
type EventPublisher interface {
PublishEvent(ctx context.Context, subject string, payload any) error
}
EventPublisher defines the contract for transactional or in-memory event publishing.
func EventPublisherFrom ¶
func EventPublisherFrom(ctx context.Context) (EventPublisher, bool)
EventPublisherFrom retrieves the event publisher from context.
type Key ¶
type Key[T any] struct { // contains filtered or unexported fields }
Key is a typed context key.
type RequestScope ¶
type RequestScope struct {
RequestID string
Endpoint string
UserID string
TenantID string
TraceID string
Role string
Roles []string
Permissions []string
Features []string
ClientIP string
TraceEvents []string
}
RequestScope holds all cross-cutting data for a single request.
func ScopeFrom ¶
func ScopeFrom(ctx context.Context) *RequestScope
func (*RequestScope) Reset ¶
func (s *RequestScope) Reset()
Click to show internal directories.
Click to hide internal directories.