-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.go
88 lines (70 loc) · 1.46 KB
/
index.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
84
85
86
87
88
package main
import (
"flag"
"github.com/coral"
"github.com/coral/cache"
"github.com/coral/config"
"github.com/coral/db"
"github.com/coral/log"
. "github.com/mahjong/constant"
"github.com/mahjong/filter"
)
var conf config.Configer
func initDB() {
// add default db
db.AddDB(
DEF_DB,
conf.String("db.DB_DSN"),
conf.Int("db.DB_MAX_CONNECTION"),
conf.Int("db.DB_MAX_IDLE"))
// add other db
// ...
}
func initRedis() {
// add default cache
cache.AddRedis(
DEF_REDIS,
conf.String("cache.REDIS_SERVER"),
conf.String("cache.REDIS_AUTH"),
conf.Int("cache.REDIS_MAX_CONNECTION"),
conf.Int("cache.REDIS_MAX_IDLE"))
// add other cache
// ...
}
func initLog() {
// add default logger
log.AddLogger(
DEF_LOG,
conf.String("log.LOG_PATH"),
conf.Int("log.LOG_MAX_NUMBER"),
conf.Int64("log.LOG_MAX_SIZE"),
conf.Int("log.LOG_MAX_LEVEL"),
conf.Int("log.LOG_MIN_LEVEL"))
// add other logger
// ...
}
func initRouter(server *coral.Server) {
filter.InitRouter(server)
}
func main() {
confFile := flag.String("ini", "./config/config.ini", "your config file")
flag.Parse()
if *confFile != "" {
config.AddConfiger(config.INI, DEF_CONF, *confFile)
conf = config.Use(DEF_CONF)
// init log
initLog()
// init db
initDB()
// init redis
initRedis()
// new server
server := coral.NewServer(conf.Get("server.HOST"))
// init router
initRouter(server)
// start server
server.Run()
} else {
panic("run with -h to find usage")
}
}