-
Notifications
You must be signed in to change notification settings - Fork 14
/
oss.go
52 lines (42 loc) · 1.44 KB
/
oss.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
package registry
import (
"errors"
"github.com/latolukasz/beeorm"
"github.com/sarulabs/di"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/app"
"github.com/coretrix/hitrix/service/component/clock"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/oss"
)
func ServiceProviderOSS(bucketsMapping map[string]*oss.Bucket, ossProvider int) *service.DefinitionGlobal {
return &service.DefinitionGlobal{
Name: service.OSService,
Build: func(ctn di.Container) (interface{}, error) {
if len(bucketsMapping) == 0 {
panic("buckets mapping not defined")
}
ormConfig := ctn.Get(service.ORMConfigService).(beeorm.ValidatedRegistry)
entities := ormConfig.GetEntities()
if _, ok := entities["entity.OSSBucketCounterEntity"]; !ok {
return nil, errors.New("you should register OSSBucketCounterEntity")
}
configService := ctn.Get(service.ConfigService).(config.IConfig)
clockService := ctn.Get(service.ClockService).(clock.IClock)
if ossProvider == oss.ProviderGoogleOSS {
return oss.NewGoogleOSS(
configService,
clockService,
bucketsMapping,
ctn.Get(service.AppService).(*app.App).Mode)
} else if ossProvider == oss.ProviderAmazonOSS {
return oss.NewAmazonOSS(
configService,
clockService,
bucketsMapping,
ctn.Get(service.AppService).(*app.App).Mode)
}
panic("invalid oss provider")
},
}
}