Help us shape the future of Go! Take the 2026 Go Developer Survey

ctx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Claims

func Claims[T any](ctx context.Context) (T, bool)

Claims loads claims of type T from ctx. Returns (zero, false) if not present or type mismatch.

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request_id stored in ctx, or empty string if not set.

func Scopes

func Scopes(ctx context.Context) []string

Scopes returns the scopes stored in ctx.

The returned slice is a copy to prevent caller mutation. If not set, returns nil.

func SubjectID

func SubjectID(ctx context.Context) string

SubjectID returns the subject_id stored in ctx, or empty string if not set.

func TenantID

func TenantID(ctx context.Context) string

TenantID returns the tenant_id stored in ctx, or empty string if not set.

func WithClaims

func WithClaims[T any](ctx context.Context, claims T) context.Context

WithClaims stores arbitrary claims in context. Use sparingly. Defensive behavior: if ctx is nil, it is treated as context.Background().

func WithRequestID

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

WithRequestID returns a derived context carrying request_id.

Defensive behavior: if ctx is nil, it is treated as context.Background(). Empty requestID is ignored (ctx returned unchanged).

func WithScopes

func WithScopes(ctx context.Context, scopes []string) context.Context

WithScopes returns a derived context carrying scopes ([]string).

The slice is copied on write to prevent caller mutation. Defensive behavior: if ctx is nil, it is treated as context.Background(). Empty scopes is ignored (ctx returned unchanged).

func WithSubjectID

func WithSubjectID(ctx context.Context, subjectID string) context.Context

WithSubjectID returns a derived context carrying subject_id (sub).

Defensive behavior: if ctx is nil, it is treated as context.Background(). Empty subjectID is ignored (ctx returned unchanged).

func WithTenantID

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

WithTenantID returns a derived context carrying tenant_id.

Defensive behavior: if ctx is nil, it is treated as context.Background(). Empty tenantID is ignored (ctx returned unchanged).

Types

This section is empty.

Jump to

Keyboard shortcuts

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