forked from dwg255/landlord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (47 loc) · 1.36 KB
/
config.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
package main
import (
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/logs"
"landlord/common"
"os"
)
var (
gameConf = &common.GameConfInfo
)
func initConf() (err error) {
environment := os.Getenv("ENV")
if environment != "dev" && environment != "testing" && environment != "product" {
environment = "product"
}
logs.Info("the running environment is : %s", environment)
conf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
logs.Error("new conf failed ,err : %v", err)
return
}
environment += "::"
gameConf.HttpPort, err = conf.Int(environment + "http_port")
if err != nil {
logs.Error("init http_port failed,err: %v", err)
return
}
logs.Debug("read conf succ , http port : %v", gameConf.HttpPort)
//todo 日志配置
gameConf.LogPath = conf.String(environment + "log_path")
if len(gameConf.LogPath) == 0 {
gameConf.LogPath = "./logs/game.log"
}
logs.Debug("read conf succ , LogPath : %v", gameConf.LogPath)
gameConf.LogLevel = conf.String(environment + "log_level")
if len(gameConf.LogLevel) == 0 {
gameConf.LogLevel = "debug"
}
logs.Debug("read conf succ , LogLevel : %v", gameConf.LogLevel)
//todo sqlite配置
gameConf.DbPath = conf.String(environment + "db_path")
if len(gameConf.DbPath) == 0 {
gameConf.DbPath = "./db/landlord.db"
}
logs.Debug("read conf succ , DbPath : %v", gameConf.DbPath)
return
}