tenant

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderKey = "x-tenant-slug"

HeaderKey is the Kafka header key for tenant slug propagation between services.

View Source
const TenantSlugHeader = "X-Tenant-Slug"

TenantSlugHeader is the HTTP header used to propagate tenant slug between services.

Variables

View Source
var ErrTenantNotFound = errors.New("tenant not found")

ErrTenantNotFound is returned when tenant slug is not present in the request.

Functions

func ContextFromKafkaHeaders

func ContextFromKafkaHeaders(ctx context.Context, headers []kgo.RecordHeader) context.Context

ContextFromKafkaHeaders creates a context with the tenant ID extracted from Kafka record headers. If no tenant ID is present in headers, returns the context unchanged.

func ContextWithSlug

func ContextWithSlug(ctx context.Context, slug string) context.Context

ContextWithSlug returns a new context with the tenant slug stored.

func Middleware

func Middleware(log *zap.Logger) middleware.Middleware

Middleware resolves tenant slug from the X-Tenant-Slug header and stores it in context. It also validates that user tokens have a tenant claim matching the request tenant.

func MiddlewareModule

func MiddlewareModule() fx.Option

MiddlewareModule provides tenant resolution as an ogen middleware. Priority 25: after Recovery(10) and Logger(20), before Timeout(30).

func MustSlugFromContext

func MustSlugFromContext(ctx context.Context) string

MustSlugFromContext retrieves the tenant slug from the context. Panics if tenant slug is not present — use only in code paths where tenant middleware has already validated the presence.

func SaveToHeaders

func SaveToHeaders(ctx context.Context, headers map[string]string) map[string]string

SaveToHeaders adds the tenant slug from context to the headers map. Returns the (possibly modified) headers map. If no tenant is in context, returns headers unchanged.

func SlugFromContext

func SlugFromContext(ctx context.Context) (string, bool)

SlugFromContext retrieves the tenant slug from the context. Returns the slug and true if present, empty string and false otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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