-
Notifications
You must be signed in to change notification settings - Fork 14
/
service.go
126 lines (105 loc) · 3.02 KB
/
service.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package service
import (
"context"
"github.com/coretrix/hitrix/service/component/oss"
errorlogger "github.com/coretrix/hitrix/service/component/error_logger"
slackapi "github.com/coretrix/hitrix/service/component/slack_api"
"github.com/coretrix/hitrix/service/component/config"
"github.com/coretrix/hitrix/service/component/jwt"
"github.com/coretrix/hitrix/service/component/password"
"github.com/coretrix/hitrix/service/component/app"
"github.com/latolukasz/orm"
)
const (
AppService = "app"
ConfigService = "config"
ErrorLoggerService = "error_logger"
JWTService = "jwt"
DDOSService = "ddos"
ORMConfigService = "orm_config"
ORMEngineGlobalService = "orm_engine_global"
ORMEngineRequestService = "orm_engine_request"
OSSGoogleService = "oss_google"
PasswordService = "password"
SlackAPIService = "slack_api"
)
type DIInterface interface {
App() *app.App
Config() *config.Config
OrmConfig() (orm.ValidatedRegistry, bool)
OrmEngine() (*orm.Engine, bool)
OrmEngineForContext(ctx context.Context) (*orm.Engine, bool)
JWT() (*jwt.JWT, bool)
Password() (*password.Password, bool)
SlackAPI() (*slackapi.SlackAPI, bool)
ErrorLogger() (errorlogger.ErrorLogger, bool)
OSSGoogle() (oss.Client, bool)
}
type diContainer struct {
}
var dicInstance = &diContainer{}
func DI() DIInterface {
return dicInstance
}
func (d *diContainer) App() *app.App {
return GetServiceRequired(AppService).(*app.App)
}
func (d *diContainer) Config() *config.Config {
return GetServiceRequired(ConfigService).(*config.Config)
}
func (d *diContainer) OrmConfig() (orm.ValidatedRegistry, bool) {
v, has := GetServiceOptional(ORMConfigService)
if has {
return v.(orm.ValidatedRegistry), true
}
return nil, false
}
func (d *diContainer) OrmEngine() (*orm.Engine, bool) {
v, has := GetServiceOptional(ORMEngineGlobalService)
if has {
return v.(*orm.Engine), true
}
return nil, false
}
func (d *diContainer) OrmEngineForContext(ctx context.Context) (*orm.Engine, bool) {
v, has := GetServiceForRequestOptional(ctx, ORMEngineRequestService)
if has {
return v.(*orm.Engine), true
}
return nil, false
}
func (d *diContainer) JWT() (*jwt.JWT, bool) {
v, has := GetServiceOptional(JWTService)
if has {
return v.(*jwt.JWT), true
}
return nil, false
}
func (d *diContainer) Password() (*password.Password, bool) {
v, has := GetServiceOptional(PasswordService)
if has {
return v.(*password.Password), true
}
return nil, false
}
func (d *diContainer) SlackAPI() (*slackapi.SlackAPI, bool) {
v, has := GetServiceOptional(SlackAPIService)
if has {
return v.(*slackapi.SlackAPI), true
}
return nil, false
}
func (d *diContainer) ErrorLogger() (errorlogger.ErrorLogger, bool) {
v, has := GetServiceOptional(ErrorLoggerService)
if has {
return v.(errorlogger.ErrorLogger), true
}
return nil, false
}
func (d *diContainer) OSSGoogle() (oss.Client, bool) {
v, has := GetServiceOptional(OSSGoogleService)
if has {
return v.(oss.Client), true
}
return nil, false
}