-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (38 loc) · 821 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 (
"goqtt/config"
"goqtt/logger"
"goqtt/server"
"goqtt/workers"
"os"
"os/signal"
"runtime"
"syscall"
)
func main() {
confFile := os.Getenv("CONFIG_PATH")
if confFile == "" {
confFile = "config/config.json"
}
config, err := config.LoadConfig(confFile)
if err != nil {
panic(err)
}
logger.Init(config.Logger)
workers.GlobalPool = workers.NewPool(config.Pool)
workers.GlobalPool.StartWorkers(runtime.NumCPU())
srv := server.NewServer(config.Connector)
if srv == nil {
logger.HTTP.Panic().Err(err).Msg("Couldn't create a server")
}
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
go func() {
<-quit
logger.Default.Info().Msg("Shutting down server")
srv.Stop()
workers.GlobalPool.StopWorkers()
os.Exit(0)
}()
srv.Start()
}