main.go
1.88 KB
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
84
85
86
87
88
89
90
91
92
package main
import (
"HttpServer/conf"
"HttpServer/jsonconf"
"mysql"
"HttpServer/logic"
"HttpServer/redishandler"
"common/logger"
"flag"
"os"
"runtime/pprof"
"time"
)
func InitLogger(file string, lvl int) {
logger.New(file, lvl, logger.Rotate{Size: logger.GB, Expired: time.Hour * 24 * 7, Interval: time.Hour * 24})
}
func main() {
//defer utils.PrintPanicStack()
filename := flag.String("conf_path", "./conf/world.xml", "config file path")
logpath := flag.String("logpath", "./log", "log file path")
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
secs := flag.Int("exitsecs", 0, "how many secs to exit, defaut 0 to never exit")
lvl := flag.Int("lvl", 6, "log level default -debug")
flag.Parse()
InitLogger(*logpath+"/world.log", *lvl)
logger.Info("config file path:%v", *filename)
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
logger.Info("open cpu profile error %v:", err)
} else {
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
}
var ch chan int = make(chan int)
go waitFor(ch, *secs)
err := conf.LoadConf(*filename)
if err != nil {
logger.Info("error load conf fail %v:", err)
return
}
err = redishandler.Init()
if err != nil {
logger.Error("err init redis err=%v", err)
return
}
err = mysql.InitMysql()
if err != nil {
logger.Error("err init mysql err=%v", err)
return
}
err = jsonconf.LoadJsonConf()
if err != nil {
logger.Error("err load jsonconfl err=%v", err)
return
}
//測試
//logic.Test()
go logic.StartHttpServe()
go logic.StartHttpTicker()
time.Sleep(time.Duration(2) * time.Second)
logic.Testsendhttp()
select {
case _ = <-ch:
logger.Info("---I'm done----")
break
}
}
func waitFor(ch chan int, secs int) {
if secs <= 0 {
return
}
time.Sleep(time.Duration(secs) * time.Second)
logger.Info("-------------ready to exit--------------------")
ch <- 1
}