go-saas / saas

go data framework for saas(multi-tenancy)
MIT License
264 stars 44 forks source link

Domain Example #12

Open Jxckaroo opened 1 year ago

Jxckaroo commented 1 year ago

Hey 👋

Love the work!

Do you have an example of multi tenancy via domains with individual databases? For example:

Main domain: mysaasapp.com Tenant domain: tenantname.mysaasapp.com Tenant 2 domain tenanttwoname.mysaasapp.com

etc? From what I read, its supported, but unsure on implementation.

goxiaoy commented 1 year ago

change this line https://github.com/go-saas/saas/blob/0b157bcf9a4e237767611149f972a4a9ff4628d9/examples/gorm/main.go#L136-L137 to

import(
   ...
   shttp "github.com/go-saas/saas/http"
   ...
)
...
r.Use(sgin.MultiTenancy(tenantStore,
        sgin.WithMultiTenancyOption(shttp.NewWebMultiTenancyOption("", "([-a-z0-9]+)\\.mysaasapp\\.com"))))

adjust your own tenant name regex format

see https://github.com/go-saas/saas/blob/main/http/domain_tenant_resolve_contrib.go