xcontext

package
v2.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JwtCtxKey is the key used to store the JWT (raw) string in the context
	JwtCtxKey = "as-jwt-token"
	// UserCtxKey is the key used to store the user in the context
	UserCtxKey = "x-user"
	// ImpersonatingUserKeyName is the key used to store the impersonating (real)
	// user in the context
	ImpersonatingUserKeyName = "x-real-user"
	// TenantCtxKey is the key used to store the tenant in the context. If present
	// it will be used in case the user is not present.
	TenantCtxKey = "x-tenant"

	// DefaultTenant is the tenant to use if no tenant is found in the context
	DefaultTenant = "default"
)

Variables

This section is empty.

Functions

func GetTenant

func GetTenant(ctx context.Context) (tenant string, found bool)

GetTenant returns the tenant from the context if it exists.

func GetTenantOrDefault

func GetTenantOrDefault(ctx context.Context) string

GetTenantOrDefault returns the tenant from the context if it exists or the default value.

func GetUser

func GetUser(ctx context.Context) (xuser.User, error)

GetUser returns the user from the context if it exists. If the user does not exist, returns an unauthorized error.

func MustGetUser

func MustGetUser(ctx context.Context) xuser.User

MustGetUser returns the user from the context if it exists. If the user does not exist, it panics.

func WithJwt

func WithJwt(ctx context.Context, jwt string) context.Context

WithJwt returns a new context with the jwt set.

func WithTenant

func WithTenant(ctx context.Context, tenant string) context.Context

WithTenant returns a new context with the tenant set.

func WithUser

func WithUser(ctx context.Context, user xuser.User) context.Context

WithUser returns a new context with the user set.

Types

This section is empty.

Jump to

Keyboard shortcuts

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