-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
83 lines (62 loc) · 1.23 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"arutam/common/db"
"arutam/common/redis"
"arutam/routes"
"arutam/tools/cfg"
"flag"
log "github.com/alecthomas/log4go"
"math"
"runtime"
"github.com/gin-gonic/gin"
)
func main() {
_init()
port := cfg.Get("env", "port").String()
if port == ""{
port = "8282"
}
routes.Bind(port)
defer _deferer()
}
func init() {
ConfPath := flag.String("c", "", " set arutam config file path")
flag.Parse()
cfg.ConfPath = string(*ConfPath)
NumCPU := runtime.NumCPU()
runtime.GOMAXPROCS(int(math.Max(float64(NumCPU-1), 1)))
log.LoadConfiguration(cfg.ConfPath + "config/log.xml")
}
func _init() {
_check_config()
_check_language()
_check_online()
db.InitMySQL()
myredis.InitRedis()
}
func _deferer() {
db.CloseMySQL()
myredis.CloseRedis()
log.Close()
}
/*检查配置文件格式*/
func _check_config() {
filename, _ := cfg.WalkDir("config", "")
for _, s := range filename {
cfg.Valid(s)
}
log.Info("init check config success")
}
func _check_language() {
filename, _ := cfg.WalkDir("i18n", "")
for _, s := range filename {
cfg.Valid(s)
}
log.Info("init check language config success")
}
func _check_online() {
dev := cfg.Get("env", "dev").Bool()
if !dev {
gin.SetMode(gin.ReleaseMode)
}
}