Documentation
¶
Index ¶
- func DB(c *nhttp.Context) *lucid.DB
- func ID(c *nhttp.Context) string
- type Config
- type GormStore
- func (s *GormStore) All(_ context.Context) ([]*Tenant, error)
- func (s *GormStore) Delete(_ context.Context, id string) error
- func (s *GormStore) FindByDomain(_ context.Context, domain string) (*Tenant, error)
- func (s *GormStore) FindByID(_ context.Context, id string) (*Tenant, error)
- func (s *GormStore) Save(_ context.Context, tenant *Tenant) error
- type Manager
- func (m *Manager) Get(id string) (*Tenant, bool)
- func (m *Manager) Middleware() router.Middleware
- func (m *Manager) Register(t *Tenant)
- func (m *Manager) Resolve(r *http.Request) (string, error)
- func (m *Manager) ScopeDB(tenant *Tenant) (*lucid.DB, error)
- func (m *Manager) SetStore(store TenantStore)
- type ResolveMethod
- type Strategy
- type Tenant
- type TenantPlugin
- type TenantStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
ResolveBy ResolveMethod
HeaderName string // for ResolveHeader (default: X-Tenant-ID)
PathPrefix string // for ResolvePath (default: first path segment)
Strategy Strategy
DefaultDB *lucid.DB // the main database connection
DBResolver func(tenant *Tenant) (*lucid.DB, error) // for StrategyDatabase
CustomResolver func(r *http.Request) (string, error) // for ResolveCustom
}
Config configures the tenancy system.
type GormStore ¶
type GormStore struct {
// contains filtered or unexported fields
}
GormStore implements TenantStore using GORM.
func NewGormStore ¶
NewGormStore creates a GORM-backed tenant store.
func (*GormStore) FindByDomain ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles tenant resolution and database scoping.
func (*Manager) Middleware ¶
func (m *Manager) Middleware() router.Middleware
Middleware returns the tenancy resolution middleware.
func (*Manager) SetStore ¶
func (m *Manager) SetStore(store TenantStore)
SetStore configures the tenant store.
type ResolveMethod ¶
type ResolveMethod string
ResolveMethod defines how the tenant is identified from requests.
const ( ResolveSubdomain ResolveMethod = "subdomain" ResolveHeader ResolveMethod = "header" ResolvePath ResolveMethod = "path" ResolveCustom ResolveMethod = "custom" )
type Tenant ¶
type Tenant struct {
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
Domain string `json:"domain,omitempty"`
Schema string `json:"schema,omitempty"`
DBName string `json:"db_name,omitempty"`
Metadata map[string]string `json:"metadata,omitempty" gorm:"-"`
Active bool `json:"active" gorm:"default:true"`
}
Tenant represents a single tenant.
type TenantPlugin ¶
type TenantPlugin struct {
nimbus.BasePlugin
Manager *Manager
}
TenantPlugin integrates multi-tenancy with Nimbus.
func (*TenantPlugin) Middleware ¶
func (p *TenantPlugin) Middleware() map[string]router.Middleware
func (*TenantPlugin) RegisterRoutes ¶
func (p *TenantPlugin) RegisterRoutes(r *router.Router)
type TenantStore ¶
type TenantStore interface {
FindByID(ctx context.Context, id string) (*Tenant, error)
FindByDomain(ctx context.Context, domain string) (*Tenant, error)
All(ctx context.Context) ([]*Tenant, error)
Save(ctx context.Context, tenant *Tenant) error
Delete(ctx context.Context, id string) error
}
TenantStore is the interface for loading/saving tenants.
Click to show internal directories.
Click to hide internal directories.