-
Notifications
You must be signed in to change notification settings - Fork 44
/
tenant_resolve_option.go
48 lines (40 loc) · 1.08 KB
/
tenant_resolve_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
44
45
46
47
48
package saas
type TenantResolveOption struct {
Resolvers []TenantResolveContrib
}
type ResolveOption func(resolveOption *TenantResolveOption)
func AppendContribs(c ...TenantResolveContrib) ResolveOption {
return func(resolveOption *TenantResolveOption) {
resolveOption.AppendContribs(c...)
}
}
func RemoveContribs(c ...TenantResolveContrib) ResolveOption {
return func(resolveOption *TenantResolveOption) {
resolveOption.RemoveContribs(c...)
}
}
func NewTenantResolveOption(c ...TenantResolveContrib) *TenantResolveOption {
return &TenantResolveOption{
Resolvers: c,
}
}
func (opt *TenantResolveOption) AppendContribs(c ...TenantResolveContrib) {
opt.Resolvers = append(opt.Resolvers, c...)
}
func (opt *TenantResolveOption) RemoveContribs(c ...TenantResolveContrib) {
var r []TenantResolveContrib
for _, resolver := range opt.Resolvers {
if !contains(c, resolver) {
r = append(r, resolver)
}
}
opt.Resolvers = r
}
func contains(a []TenantResolveContrib, b TenantResolveContrib) bool {
for i := 0; i < len(a); i++ {
if a[i] == b {
return true
}
}
return false
}