forked from git1234567outlookcom/topology-server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
61 lines (49 loc) · 1.11 KB
/
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
package main
import (
"flag"
"os"
"runtime"
"time"
"topology/config"
"topology/db"
"topology/db/mongo"
"topology/router"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
func main() {
debug := flag.Bool("debug", false, "Sets log level to debug.")
flag.Parse()
zerolog.SetGlobalLevel(zerolog.InfoLevel)
if *debug {
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339})
// 处理panic
defer func() {
if err := recover(); err != nil {
log.Panic().Msgf("%v", err)
}
}()
// 初始化配置
config.Init()
// 设置日志
if config.App.Log.Filename != "" {
log.Logger = log.Output(&lumberjack.Logger{
Filename: config.App.Log.Filename,
MaxSize: config.App.Log.MaxSize, // mb
MaxBackups: config.App.Log.MaxBackups,
MaxAge: config.App.Log.MaxAge, // days
})
}
// 最大cpu使用核心数
runtime.GOMAXPROCS(config.App.CPU)
// 数据库连接
if !db.Init() {
return
}
defer mongo.Session.Close()
// 监听路由
router.Listen()
}