-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootx.go
71 lines (67 loc) · 1.38 KB
/
bootx.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
package bootx
type Application interface {
GetName() string
GetVersion() string
Bootstrap()
Shutdown()
}
func Bootstrap(app Application, configs ...interface{}) {
appName := app.GetName()
appVersion := app.GetVersion()
logger.Printf("%s %s bootstrap ...", appName, appVersion)
initKernel()
defer cleanupKernel()
webConf, dbConf, redisConf := initModules(configs...)
//if no gWebX config ,use default config
if !webConf {
webInit()
}
if dbConf {
defer dbCleanup()
}
if redisConf {
defer redisCleanup()
}
app.Bootstrap()
defer app.Shutdown()
//start gWebX service
Web().start()
defer Web().stop()
getKernel().waitForExit()
}
func Kill() {
getKernel().kill()
}
func initModules(configs ...interface{}) (webConf, dbConf, redisConf bool) {
for _, conf := range configs {
switch c := conf.(type) {
case WebConfig:
webInitWithConfig(c)
case *WebConfig:
webInitWithConfig(*c)
webConf = true
case DBConfig:
dbInitWithConfig([]DBConfig{c})
dbConf = true
case *DBConfig:
dbInitWithConfig([]DBConfig{*c})
dbConf = true
case []DBConfig:
dbInitWithConfig(c)
dbConf = true
case []*DBConfig:
ds := make([]DBConfig, 0, len(c))
for _, db := range c {
ds = append(ds, *db)
}
dbInitWithConfig(ds)
dbConf = true
case RedisConfig:
redisInitWithConfig(c)
case *RedisConfig:
redisInitWithConfig(*c)
redisConf = true
}
}
return
}