-
Notifications
You must be signed in to change notification settings - Fork 14
/
feature_flag.go
54 lines (44 loc) · 1.92 KB
/
feature_flag.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
49
50
51
52
53
54
package registry
import (
"errors"
"github.com/latolukasz/beeorm/v2"
"github.com/sarulabs/di"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/clock"
errorlogger "github.com/coretrix/hitrix/service/component/error_logger"
featureflag "github.com/coretrix/hitrix/service/component/feature_flag"
)
type FeatureFlagRegistryInitFunc func(flagInterface featureflag.ServiceFeatureFlagInterface)
func ServiceProviderFeatureFlag(registry FeatureFlagRegistryInitFunc) *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.FeatureFlagService,
Build: func(ctn di.Container) (interface{}, error) {
ormConfig := ctn.Get(service.ORMConfigService).(beeorm.ValidatedRegistry)
entities := ormConfig.GetEntities()
if _, ok := entities["entity.FeatureFlagEntity"]; !ok {
return nil, errors.New("you should register FeatureFlagEntity")
}
errorLoggerService := ctn.Get(service.ErrorLoggerService).(errorlogger.ErrorLogger)
featureFlagService := featureflag.NewFeatureFlagService(errorLoggerService)
registry(featureFlagService)
return featureFlagService, nil
},
}
}
func ServiceProviderFeatureFlagWithCache(registry FeatureFlagRegistryInitFunc) *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.FeatureFlagService,
Build: func(ctn di.Container) (interface{}, error) {
ormConfig := ctn.Get(service.ORMConfigService).(beeorm.ValidatedRegistry)
entities := ormConfig.GetEntities()
if _, ok := entities["entity.FeatureFlagEntity"]; !ok {
return nil, errors.New("you should register FeatureFlagEntity")
}
errorLoggerService := ctn.Get(service.ErrorLoggerService).(errorlogger.ErrorLogger)
clockService := ctn.Get(service.ClockService).(clock.IClock)
featureFlagService := featureflag.NewFeatureFlagWithCacheService(errorLoggerService, clockService)
registry(featureFlagService)
return featureFlagService, nil
},
}
}