context

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

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

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 AddAuthHeaderToContext(ctx context.Context, headerValue string) context.Context

func AddIsTechnicalIssuerToContext

func AddIsTechnicalIssuerToContext(ctx context.Context) context.Context

func AddSpiffeToContext

func AddSpiffeToContext(ctx context.Context, spiffe string) context.Context

func AddTenantToContext

func AddTenantToContext(ctx context.Context, tenantId string) context.Context

func AddWebTokenToContext

func AddWebTokenToContext(ctx context.Context, idToken string) context.Context

func GetAuthHeaderFromContext

func GetAuthHeaderFromContext(ctx context.Context) (string, error)

func GetIsTechnicalIssuerFromContext

func GetIsTechnicalIssuerFromContext(ctx context.Context) bool

func GetSpiffeFromContext

func GetSpiffeFromContext(ctx context.Context) (string, error)

func GetTenantFromContext

func GetTenantFromContext(ctx context.Context) (string, error)

func GetWebTokenFromContext

func GetWebTokenFromContext(ctx context.Context) (jwt.WebToken, error)

func HasTenantInContext added in v0.13.0

func HasTenantInContext(ctx context.Context) bool

func NotifyShutdownContext

func NotifyShutdownContext(parent context.Context) (ctx context.Context, stop context.CancelFunc)

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

func Recover(log *logger.Logger)

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

func StartContext

func StartContext(log *logger.Logger, cfg any, timeout time.Duration) (ctx context.Context, cancel context.CancelCauseFunc, shutdown func())

Creates a new context and returns context, cancel and shutdown function. It should be directly followed by a defer call to shutdown.

func TimeoutFromContext

func TimeoutFromContext(ctx context.Context) time.Duration

Returns the wrapped timeout inside the context and will return a default timeout of 3 seconds when the context does not exist or doesn't wrap a timeout.

Types

type ContextKey added in v0.5.0

type ContextKey string

type ShutdownTimeoutKey

type ShutdownTimeoutKey struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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