Documentation ¶
Overview ¶
Package context implements a safe way to create a context which will have a timeout after closing the context
The basic usage is using the StartContext function with a direct defer call to shutdown afterwards. There is a Timeout set in the context so TimeoutFromContext will return the time this context will wait for subroutines to stop.
Index ¶
- Constants
- Variables
- func AddAuthHeaderToContext(ctx context.Context, headerValue string) context.Context
- func AddIsTechnicalIssuerToContext(ctx context.Context) context.Context
- func AddSpiffeToContext(ctx context.Context, spiffe string) context.Context
- func AddTenantToContext(ctx context.Context, tenantId string) context.Context
- func AddWebTokenToContext(ctx context.Context, idToken string) context.Context
- func GetAuthHeaderFromContext(ctx context.Context) (string, error)
- func GetIsTechnicalIssuerFromContext(ctx context.Context) bool
- func GetSpiffeFromContext(ctx context.Context) (string, error)
- func GetTenantFromContext(ctx context.Context) (string, error)
- func GetWebTokenFromContext(ctx context.Context) (jwt.WebToken, error)
- func HasTenantInContext(ctx context.Context) bool
- func NotifyShutdownContext(parent context.Context) (ctx context.Context, stop context.CancelFunc)
- func Recover(log *logger.Logger)
- func StartContext(log *logger.Logger, cfg any, timeout time.Duration) (ctx context.Context, cancel context.CancelCauseFunc, shutdown func())
- func TimeoutFromContext(ctx context.Context) time.Duration
- type ContextKey
- type ShutdownTimeoutKey
Constants ¶
const DefaultShutdownTimeout = 3 * time.Second
Can be used in StartContext to have a sane default timeout
Variables ¶
var ShutdownError = errors.New("shutdown")
Functions ¶
func AddAuthHeaderToContext ¶
func AddSpiffeToContext ¶
func AddTenantToContext ¶
func AddWebTokenToContext ¶
func GetWebTokenFromContext ¶
func HasTenantInContext ¶ added in v0.13.0
func NotifyShutdownContext ¶
NotifyShutdownContext returns a copy of the parent context that is marked done (its Done channel is closed) when one of the expected signals arrives, when the returned stop function is called, or when the parent context's Done channel is closed, whichever happens first.
func Recover ¶ added in v0.5.0
Recover can be used as deferred function to catch panics This function is used in the context of context creation. Its contained in the context package to avoid circular dependencies with sentry package
Types ¶
type ContextKey ¶ added in v0.5.0
type ContextKey string
type ShutdownTimeoutKey ¶
type ShutdownTimeoutKey struct{}