-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecorator_config.go
More file actions
73 lines (59 loc) · 2.04 KB
/
decorator_config.go
File metadata and controls
73 lines (59 loc) · 2.04 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package modular
import (
"errors"
)
// instanceAwareConfigDecorator implements instance-aware configuration decoration
type instanceAwareConfigDecorator struct{}
// DecorateConfig applies instance-aware configuration decoration
func (d *instanceAwareConfigDecorator) DecorateConfig(base ConfigProvider) ConfigProvider {
return &instanceAwareConfigProvider{
base: base,
}
}
// Name returns the decorator name for debugging
func (d *instanceAwareConfigDecorator) Name() string {
return "InstanceAware"
}
// instanceAwareConfigProvider wraps a config provider to add instance awareness
type instanceAwareConfigProvider struct {
base ConfigProvider
}
// GetConfig returns the base configuration
func (p *instanceAwareConfigProvider) GetConfig() any {
return p.base.GetConfig()
}
// tenantAwareConfigDecorator implements tenant-aware configuration decoration
type tenantAwareConfigDecorator struct {
loader TenantLoader
}
// DecorateConfig applies tenant-aware configuration decoration
func (d *tenantAwareConfigDecorator) DecorateConfig(base ConfigProvider) ConfigProvider {
return &tenantAwareConfigProvider{
base: base,
loader: d.loader,
}
}
// Name returns the decorator name for debugging
func (d *tenantAwareConfigDecorator) Name() string {
return "TenantAware"
}
// tenantAwareConfigProvider wraps a config provider to add tenant awareness
type tenantAwareConfigProvider struct {
base ConfigProvider
loader TenantLoader
}
// GetConfig returns the base configuration
func (p *tenantAwareConfigProvider) GetConfig() any {
return p.base.GetConfig()
}
// Predefined error for missing tenant loader
var errNoTenantLoaderConfigured = errors.New("no tenant loader configured")
// GetTenantConfig retrieves configuration for a specific tenant
func (p *tenantAwareConfigProvider) GetTenantConfig(tenantID TenantID) (any, error) {
if p.loader == nil {
return nil, errNoTenantLoaderConfigured
}
// This is a simplified implementation - in a real scenario,
// you'd load tenant-specific configuration from the tenant loader
return p.base.GetConfig(), nil
}