Documentation
¶
Index ¶
- Constants
- Variables
- func ContextFromKafkaHeaders(ctx context.Context, headers []kgo.RecordHeader) context.Context
- func ContextWithSlug(ctx context.Context, slug string) context.Context
- func Middleware(log *zap.Logger) middleware.Middleware
- func MiddlewareModule() fx.Option
- func MustSlugFromContext(ctx context.Context) string
- func SaveToHeaders(ctx context.Context, headers map[string]string) map[string]string
- func SlugFromContext(ctx context.Context) (string, bool)
Constants ¶
const HeaderKey = "x-tenant-slug"
HeaderKey is the Kafka header key for tenant slug propagation between services.
const TenantSlugHeader = "X-Tenant-Slug"
TenantSlugHeader is the HTTP header used to propagate tenant slug between services.
Variables ¶
var ErrTenantNotFound = errors.New("tenant not found")
ErrTenantNotFound is returned when tenant slug is not present in the request.
Functions ¶
func ContextFromKafkaHeaders ¶
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 ¶
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 ¶
MiddlewareModule provides tenant resolution as an ogen middleware. Priority 25: after Recovery(10) and Logger(20), before Timeout(30).
func MustSlugFromContext ¶
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 ¶
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.
Types ¶
This section is empty.