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 NotifyShutdownContext(parent context.Context) (ctx context.Context, stop context.CancelFunc)
- 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 AuthContextKey
- type ShutdownTimeoutKey
Constants ¶
View Source
const DefaultShutdownTimeout = 3 * time.Second
Can be used in StartContext to have a sane default timeout
Variables ¶
View Source
var ShutdownError = errors.New("shutdown")
Functions ¶
func AddAuthHeaderToContext ¶
func AddSpiffeToContext ¶
func AddTenantToContext ¶
func AddWebTokenToContext ¶
func GetWebTokenFromContext ¶
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.
Types ¶
type AuthContextKey ¶
type AuthContextKey string
type ShutdownTimeoutKey ¶
type ShutdownTimeoutKey struct{}
Click to show internal directories.
Click to hide internal directories.