forked from ggymm/data-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (40 loc) · 780 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
package main
import (
"os"
"os/signal"
"syscall"
"time"
"data-view/config"
"data-view/logger"
)
func main() {
state := 1
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
config.Init()
injector, cleanFunc, err := BuildInjector()
if err != nil {
panic(err)
}
router := injector.Router.NewRouter()
go func() {
_ = router.Run(config.Instance.App.Addr)
}()
EXIT:
for {
sig := <-sc
logger.Instance.Infof("接收到信号[%s]", sig.String())
switch sig {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
state = 0
break EXIT
case syscall.SIGHUP:
default:
break EXIT
}
}
cleanFunc()
logger.Instance.Infof("服务退出")
time.Sleep(time.Second)
os.Exit(state)
}