Documentation
¶
Overview ¶
Package saas turns a togo app into a multi-tenant SaaS. It resolves the current tenant from each request — by domain/subdomain or a tenant-id/team header — and scopes the app to it, with two isolation strategies: a shared database scoped by tenant_id (row-level), or a single database per tenant (connection routing).
Enable by blank-import: `togo install togo-framework/saas`.
Config (togo.yaml / env):
SAAS_TENANT_RESOLVER = header | domain | subdomain (default: header; header = X-Tenant-ID) SAAS_ISOLATION = shared | single-db (default: shared)
In a handler: read the tenant with saas.CurrentTenant(ctx) / saas.TenantID(ctx), and get the right *sql.DB with the saas service's DB(ctx) (the kernel DB under "shared", or the tenant's own DB under "single-db").
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterResolver ¶
RegisterResolver adds (or overrides) a named tenant resolver. Call from init().
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the saas service, stored in the kernel container under "saas".
type Tenant ¶
type Tenant struct {
ID string `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Domain string `db:"domain" json:"domain"`
Plan string `db:"plan" json:"plan"`
DBDSN string `db:"db_dsn" json:"db_dsn"`
CreatedAt string `db:"created_at" json:"created_at"`
}
Tenant is an isolated customer of the app.