Documentation
¶
Overview ¶
Package tenant provides multi-tenant support with tenant isolation, configuration management, and cross-tenant operations.
Index ¶
- func TenantMiddleware(manager Manager) func(next func(context.Context) error) func(context.Context) error
- func WithTenant(ctx context.Context, tenant *Tenant) context.Context
- type DefaultManager
- func (m *DefaultManager) CheckLimit(ctx context.Context, tenantID string, limitName string, value int) error
- func (m *DefaultManager) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (m *DefaultManager) DeleteTenant(ctx context.Context, tenantID string) error
- func (m *DefaultManager) GetTenant(ctx context.Context, tenantID string) (*Tenant, error)
- func (m *DefaultManager) GetTenantByDomain(ctx context.Context, domain string) (*Tenant, error)
- func (m *DefaultManager) GetTenantContext(ctx context.Context, tenantID string) (context.Context, error)
- func (m *DefaultManager) ListTenants(ctx context.Context, filter *TenantFilter) ([]*Tenant, error)
- func (m *DefaultManager) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (m *DefaultManager) ValidateTenantAccess(ctx context.Context, tenantID string, userID string) error
- type Manager
- type Tenant
- type TenantContext
- type TenantFilter
- type TenantLimits
- type TenantStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DefaultManager ¶
type DefaultManager struct {
// contains filtered or unexported fields
}
DefaultManager implements the Manager interface
func (*DefaultManager) CheckLimit ¶
func (m *DefaultManager) CheckLimit(ctx context.Context, tenantID string, limitName string, value int) error
CheckLimit checks if a tenant has exceeded a limit
func (*DefaultManager) CreateTenant ¶
func (m *DefaultManager) CreateTenant(ctx context.Context, tenant *Tenant) error
CreateTenant creates a new tenant
func (*DefaultManager) DeleteTenant ¶
func (m *DefaultManager) DeleteTenant(ctx context.Context, tenantID string) error
DeleteTenant soft deletes a tenant
func (*DefaultManager) GetTenantByDomain ¶
GetTenantByDomain retrieves a tenant by domain
func (*DefaultManager) GetTenantContext ¶
func (m *DefaultManager) GetTenantContext(ctx context.Context, tenantID string) (context.Context, error)
GetTenantContext creates a tenant-aware context
func (*DefaultManager) ListTenants ¶
func (m *DefaultManager) ListTenants(ctx context.Context, filter *TenantFilter) ([]*Tenant, error)
ListTenants lists all tenants with optional filtering
func (*DefaultManager) UpdateTenant ¶
func (m *DefaultManager) UpdateTenant(ctx context.Context, tenant *Tenant) error
UpdateTenant updates a tenant
func (*DefaultManager) ValidateTenantAccess ¶
func (m *DefaultManager) ValidateTenantAccess(ctx context.Context, tenantID string, userID string) error
ValidateTenantAccess validates if a user has access to a tenant
type Manager ¶
type Manager interface {
// CreateTenant creates a new tenant
CreateTenant(ctx context.Context, tenant *Tenant) error
// GetTenant retrieves a tenant by ID
GetTenant(ctx context.Context, tenantID string) (*Tenant, error)
// GetTenantByDomain retrieves a tenant by domain
GetTenantByDomain(ctx context.Context, domain string) (*Tenant, error)
// UpdateTenant updates a tenant
UpdateTenant(ctx context.Context, tenant *Tenant) error
// DeleteTenant soft deletes a tenant
DeleteTenant(ctx context.Context, tenantID string) error
// ListTenants lists all tenants with optional filtering
ListTenants(ctx context.Context, filter *TenantFilter) ([]*Tenant, error)
// ValidateTenantAccess validates if a user has access to a tenant
ValidateTenantAccess(ctx context.Context, tenantID string, userID string) error
// GetTenantContext creates a tenant-aware context
GetTenantContext(ctx context.Context, tenantID string) (context.Context, error)
// CheckLimit checks if a tenant has exceeded a limit
CheckLimit(ctx context.Context, tenantID string, limitName string, value int) error
}
Manager handles tenant operations
type Tenant ¶
type Tenant struct {
ID string `json:"id" datastore:"id"`
Name string `json:"name" datastore:"name"`
Domain string `json:"domain" datastore:"domain"`
Status TenantStatus `json:"status" datastore:"status"`
Plan string `json:"plan" datastore:"plan"`
Config map[string]interface{} `json:"config" datastore:"config,noindex"`
Limits *TenantLimits `json:"limits" datastore:"limits"`
CreatedAt time.Time `json:"created_at" datastore:"created_at"`
UpdatedAt time.Time `json:"updated_at" datastore:"updated_at"`
TrialEndsAt *time.Time `json:"trial_ends_at,omitempty" datastore:"trial_ends_at"`
Metadata map[string]string `json:"metadata" datastore:"metadata,noindex"`
}
Tenant represents a tenant in the system
type TenantContext ¶
TenantContext provides tenant-aware context
type TenantFilter ¶
type TenantFilter struct {
Status TenantStatus
Plan string
Domain string
Limit int
Offset int
}
TenantFilter provides filtering options for listing tenants
type TenantLimits ¶
type TenantLimits struct {
MaxUsers int `json:"max_users" datastore:"max_users"`
MaxStorage int `json:"max_storage_gb" datastore:"max_storage_gb"`
MaxAPICallsDay int `json:"max_api_calls_day" datastore:"max_api_calls_day"`
MaxConcurrent int `json:"max_concurrent" datastore:"max_concurrent"`
CustomLimits map[string]int `json:"custom_limits" datastore:"custom_limits,noindex"`
}
TenantLimits defines resource limits for a tenant
type TenantStatus ¶
type TenantStatus string
TenantStatus represents the status of a tenant
const ( TenantStatusActive TenantStatus = "active" TenantStatusInactive TenantStatus = "inactive" TenantStatusSuspended TenantStatus = "suspended" TenantStatusTrial TenantStatus = "trial" TenantStatusDeleted TenantStatus = "deleted" )