-
Notifications
You must be signed in to change notification settings - Fork 14
/
oss.go
44 lines (34 loc) · 1.34 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
package registry
import (
"errors"
"github.com/latolukasz/orm"
"github.com/coretrix/hitrix/pkg/helper"
"github.com/coretrix/hitrix/service"
"github.com/coretrix/hitrix/service/component/app"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/oss/storage"
"github.com/sarulabs/di"
)
func OSSGoogle(buckets map[string]uint64) *service.Definition {
return &service.Definition{
Name: service.OSSGoogleService,
Global: true,
Build: func(ctn di.Container) (interface{}, error) {
configService := ctn.Get(service.ConfigService).(*config.Config)
appService := ctn.Get(service.AppService).(*app.App)
if !helper.ExistsInDir(".oss.json", configService.GetFolderPath()) {
return nil, errors.New(configService.GetFolderPath() + "/.oss.json does not exists")
}
if len(buckets) == 0 {
return nil, errors.New("please define buckets")
}
ormConfig := ctn.Get(service.ORMConfigService).(orm.ValidatedRegistry)
entities := ormConfig.GetEntities()
if _, ok := entities["entity.OSSBucketCounterEntity"]; !ok {
return nil, errors.New("ServiceDefinitionOrmRegistry should be defined before OSSGoogle")
}
ossConfig := configService.GetStringMap("oss")
return storage.NewGoogleOSS(configService.GetFolderPath()+"/.oss.json", appService.Mode, buckets, ossConfig), nil
},
}
}