middleware

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// XTenantHeader is the header key for the tenant
	XTenantHeader = "X-Tenant"
)

Variables

View Source
var (
	// DefaultSkipper represents the default skipper
	DefaultSkipper = func(r *http.Request) bool {
		return false
	}

	// DefaultTenantGetters represents the default tenant getters
	DefaultTenantGetters = []func(r *http.Request) (string, error){
		DefaultTenantFromSubdomain,
		DefaultTenantFromHeader,
	}
)
View Source
var (
	// NetHTTPTenantKey is the key that holds the tenant in the request context
	NetHTTPTenantKey = multitenancy_ctx.NetHTTPTenantKey
	// EchoTenantKey is the key that holds the tenant in the echo context
	EchoTenantKey = multitenancy_ctx.EchoTenantKey
)
View Source
var (
	// ErrTenantInvalid represents an error when the tenant is invalid or not found
	ErrTenantInvalid = fmt.Errorf("invalid tenant or tenant not found")
	// ErrDBInvalid represents an error when the database connection is invalid
	ErrDBInvalid = gorm.ErrInvalidDB
)

Functions

func DefaultTenantFromHeader

func DefaultTenantFromHeader(r *http.Request) (string, error)

DefaultTenantFromHeader retrieves the tenant from the request header

func DefaultTenantFromSubdomain

func DefaultTenantFromSubdomain(r *http.Request) (string, error)

DefaultTenantFromSubdomain retrieves the tenant from the request subdomain

Types

type WithTenantConfig

type WithTenantConfig struct {
	DB            *gorm.DB                                // DB is the database connection
	Skipper       func(r *http.Request) bool              // Skipper defines a function to skip middleware
	TenantGetters []func(r *http.Request) (string, error) // TenantGetters gets the tenant from the request; overrides the default getter
}

WithTenantConfig represents the config for the tenant middleware

Directories

Path Synopsis
gin module
iris module

Jump to

Keyboard shortcuts

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