forked from go-saas/saas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_tenancy_option.go
43 lines (35 loc) · 1008 Bytes
/
multi_tenancy_option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package saas
type DatabaseStyleType int32
const (
Single DatabaseStyleType = 1 << 0
PerTenant DatabaseStyleType = 1 << 1
Multi DatabaseStyleType = 1 << 2
)
type MultiTenancyOption struct {
IsEnabled bool
DatabaseStyle DatabaseStyleType
}
type option func(tenancyOption *MultiTenancyOption)
// WithEnabled enable status
func WithEnabled(isEnabled bool) option {
return func(tenancyOption *MultiTenancyOption) {
tenancyOption.IsEnabled = isEnabled
}
}
//
// WithDatabaseStyle database style, support Single/PerTenant/Multi
func WithDatabaseStyle(databaseStyle DatabaseStyleType) option {
return func(tenancyOption *MultiTenancyOption) {
tenancyOption.DatabaseStyle = databaseStyle
}
}
func NewMultiTenancyOption(opts ...option) *MultiTenancyOption {
option := MultiTenancyOption{}
for _, opt := range opts {
opt(&option)
}
return &option
}
func DefaultMultiTenancyOption() *MultiTenancyOption {
return NewMultiTenancyOption(WithEnabled(true), WithDatabaseStyle(Multi))
}