Documentation
¶
Overview ¶
Package ctxkit carries request-scoped identity on a context.Context.
It exists so that a service, a repository, a background goroutine and a log line all read the same trace id and the same tenant from the same place. The keys are unexported: nothing outside this package can collide with them, and nothing can put a value of the wrong type under one.
Index ¶
- func Detach(parent context.Context) context.Context
- func RequestID(ctx context.Context) string
- func Trace(ctx context.Context) string
- func WithActor(ctx context.Context, a Actor) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- func WithTenant(ctx context.Context, t Tenant) context.Context
- func WithTrace(ctx context.Context, traceID string) context.Context
- type Actor
- type Tenant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Detach ¶
Detach returns a context that keeps the trace, tenant, actor and request id of parent but NOT its cancellation or deadline.
This is the only correct way to hand work to a goroutine that outlives the request that started it. Passing the request context directly cancels the background work the moment the client disconnects — which is how fire-and-forget background work silently stops half-done.
func WithRequestID ¶
WithRequestID returns a context carrying the per-request id.
func WithTenant ¶
WithTenant returns a context scoped to one tenant.
Types ¶
type Actor ¶
type Actor struct {
UserID uuid.UUID
DeviceID string
// Roles are opaque strings; guards interpret them.
Roles []string
}
Actor is who made the request, inside the tenant.
type Tenant ¶
type Tenant struct {
AccountID uuid.UUID
// Operator is true for a platform super-admin. It does not widen the
// tenant scope on its own; a caller that wants cross-tenant reach asks for
// it explicitly.
Operator bool
}
Tenant is the ownership boundary every stored row is scoped by. A zero AccountID means "no tenant" — a platform task, a reconciler, a migration — and a repository MUST refuse to treat that as "all tenants".