-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (50 loc) · 936 Bytes
/
main.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
package main
import (
"os"
"os/signal"
"auth/assistant"
"auth/bll"
"auth/client"
"auth/collector"
log "auth/collector/logger"
"auth/config"
"auth/event"
"auth/server"
"auth/store"
sig "go-micro.dev/v4/util/signal"
)
//go:generate phanes gen -register
//go:generate swag init
type InitFunc func() func()
var bootstraps = []InitFunc{}
func main() {
var (
cancels = make([]func(), 0)
// system init func
bootstraps = []InitFunc{
config.Init,
collector.Init,
event.Init,
server.Init,
client.Init,
store.Init,
assistant.Init,
bll.Init,
}
)
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, sig.Shutdown()...)
<-sigint
for _, cancel := range cancels {
cancel()
}
close(config.ExitC)
}()
for _, fn := range bootstraps {
cancels = append(cancels, fn())
}
log.Info("finished to init all component")
<-config.ExitC
log.Info("server shutdown!")
}