tenant

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tenant provides stable tenant scoping middleware.

Use the middleware to place a tenant identifier in request context before authorization, idempotency, repositories, or audit logging need tenant-aware behavior. Invalid or missing tenant data should fail at the application edge according to the service's routing policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)

ErrorHandler handles authorization errors from the tenant middleware.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware enforces tenant scoping and stores the tenant in context.

func New

func New(opts Options) (*Middleware, error)

New creates a tenant scoping middleware.

func (*Middleware) Handler

func (m *Middleware) Handler(next http.Handler) http.Handler

Handler wraps the next handler with tenant checks.

type Options

type Options struct {
	Optional          bool
	HeaderName        string
	URLParam          string
	URLParamExtractor ports.URLParamExtractor
	TenantFromContext TenantFromContext
	ErrorHandler      ErrorHandler
}

Options configures tenant scoping.

type TenantFromContext

type TenantFromContext func(ctx context.Context) (string, bool)

TenantFromContext extracts a tenant identifier from context.

Jump to

Keyboard shortcuts

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