xctx

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ApprovalTokenKey = NewKey[string]("nexss.approval.token")

ApprovalTokenKey is the single, framework-wide context key for the approval token. Every consumer — flow, agent/permission, agent/policy reads and writes through this one key so a token minted by one package is visible to all others.

View Source
var EventPublisherKey = NewKey[EventPublisher]("nexss.event.publisher")
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 AddTrace

func AddTrace(ctx context.Context, event string)

func ApprovalTokenFrom added in v0.8.0

func ApprovalTokenFrom(ctx context.Context) string

ApprovalTokenFrom extracts the approval token, or "".

func ClientIPFrom

func ClientIPFrom(ctx context.Context) string

func CloneForAsync

func CloneForAsync(ctx context.Context) context.Context

func EndpointFrom

func EndpointFrom(ctx context.Context) string

func ExecutionIDFrom added in v0.9.3

func ExecutionIDFrom(ctx context.Context) string

func FeaturesFrom

func FeaturesFrom(ctx context.Context) []string

func FromClaims

func FromClaims(scope *RequestScope, claims map[string]any)

func HasAnyRole

func HasAnyRole(ctx context.Context, allowed ...string) bool

func HasFeature

func HasFeature(ctx context.Context, feature string) bool

func HasPermission

func HasPermission(ctx context.Context, perm string) bool

func HasRole

func HasRole(ctx context.Context, required string) bool

func PermissionsFrom

func PermissionsFrom(ctx context.Context) []string

func RequestIDFrom

func RequestIDFrom(ctx context.Context) string

func SpanIDFrom added in v0.9.3

func SpanIDFrom(ctx context.Context) string

func TenantIDFrom

func TenantIDFrom(ctx context.Context) string

func TraceIDFrom

func TraceIDFrom(ctx context.Context) string

func UserIDFrom

func UserIDFrom(ctx context.Context) string

func WithApprovalToken added in v0.8.0

func WithApprovalToken(ctx context.Context, token string) context.Context

WithApprovalToken binds an approval token to ctx.

func WithClientIP

func WithClientIP(ctx context.Context, ip string) context.Context

func WithEndpoint

func WithEndpoint(ctx context.Context, endpoint string) context.Context

func WithEventPublisher

func WithEventPublisher(ctx context.Context, pub EventPublisher) context.Context

func WithExecutionID added in v0.9.3

func WithExecutionID(ctx context.Context, id string) context.Context

func WithFeatures

func WithFeatures(ctx context.Context, features []string) context.Context

func WithPermissions

func WithPermissions(ctx context.Context, perms []string) context.Context

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

func WithRoles

func WithRoles(ctx context.Context, roles []string) context.Context

func WithScope

func WithScope(ctx context.Context, s *RequestScope) context.Context

func WithSpanID added in v0.9.3

func WithSpanID(ctx context.Context, id string) context.Context

func WithTenantID

func WithTenantID(ctx context.Context, id string) context.Context

func WithTraceContext added in v0.10.1

func WithTraceContext(ctx context.Context, traceID, spanID string) context.Context

func WithTraceID

func WithTraceID(ctx context.Context, id string) context.Context

func WithUserID

func WithUserID(ctx context.Context, id string) context.Context

Types

type EventPublisher

type EventPublisher interface {
	PublishEvent(ctx context.Context, subject string, payload any) error
}

func EventPublisherFrom

func EventPublisherFrom(ctx context.Context) (EventPublisher, bool)

type Key

type Key[T any] struct {
	// contains filtered or unexported fields
}

func NewKey

func NewKey[T any](name string) Key[T]

func (Key[T]) From

func (k Key[T]) From(ctx context.Context) (T, bool)

func (Key[T]) MustFrom

func (k Key[T]) MustFrom(ctx context.Context) T

func (Key[T]) With

func (k Key[T]) With(ctx context.Context, val T) context.Context

type RequestScope

type RequestScope struct {
	RequestID   string
	ExecutionID string
	TraceID     string
	SpanID      string
	Endpoint    string
	UserID      string
	TenantID    string
	Role        string
	ClientIP    string
	Roles       []string
	Permissions []string
	Features    []string
	TraceEvents []string
}

func NewScope

func NewScope(parent context.Context) (context.Context, *RequestScope, func())

func ScopeFrom

func ScopeFrom(ctx context.Context) *RequestScope

func (*RequestScope) Reset

func (s *RequestScope) Reset()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL