|
|
@@ -11,7 +11,13 @@ import (
|
|
|
var SerCfg *ServiceConfig
|
|
|
|
|
|
type WebConfig struct {
|
|
|
- ListenPort int
|
|
|
+ ListenAddr string
|
|
|
+ DebugMode bool
|
|
|
+}
|
|
|
+
|
|
|
+type LogConfig struct {
|
|
|
+ LogPath string
|
|
|
+ LogLevel int
|
|
|
}
|
|
|
|
|
|
type DbConfig struct {
|
|
|
@@ -34,6 +40,7 @@ type RedisConfig struct {
|
|
|
|
|
|
type ServiceConfig struct {
|
|
|
WebCfg WebConfig
|
|
|
+ LogCfg LogConfig
|
|
|
DbCfg DbConfig
|
|
|
RedisCfg RedisConfig
|
|
|
}
|
|
|
@@ -56,15 +63,44 @@ func (c *ServiceConfig) Init(path string) error {
|
|
|
// web配置
|
|
|
websettings := root.SelectElements("WebSetting")
|
|
|
for _, setting := range websettings {
|
|
|
- web_listenport := setting.SelectElement("ListenPort")
|
|
|
- if web_listenport == nil {
|
|
|
- return errors.New("read web listen port failed")
|
|
|
+ web_listenaddr := setting.SelectElement("ListenAddress")
|
|
|
+ if web_listenaddr == nil {
|
|
|
+ return errors.New("read web listen address failed")
|
|
|
+ }
|
|
|
+ SerCfg.WebCfg.ListenAddr = web_listenaddr.SelectAttrValue("values", "0.0.0.0:8080")
|
|
|
+
|
|
|
+ // 调试模式
|
|
|
+ debug_mode := setting.SelectElement("DebugMode")
|
|
|
+ if debug_mode == nil {
|
|
|
+ return errors.New("read debug mode failed")
|
|
|
}
|
|
|
- ret, err := strconv.ParseUint(web_listenport.SelectAttrValue("value", "8080"), 10, 32)
|
|
|
+ ret, err := strconv.ParseUint(debug_mode.SelectAttrValue("value", "0"), 10, 32)
|
|
|
if err != nil {
|
|
|
- return errors.New("read web listen port is invalid:")
|
|
|
+ return errors.New("read debug mode is invalid:")
|
|
|
}
|
|
|
- SerCfg.WebCfg.ListenPort = int(ret)
|
|
|
+ SerCfg.WebCfg.DebugMode = (ret == 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日志配置
|
|
|
+ logsettings := root.SelectElements("LogSetting")
|
|
|
+ for _, setting := range logsettings {
|
|
|
+ // 日志路径
|
|
|
+ log_path := setting.SelectElement("LogPath")
|
|
|
+ if log_path == nil {
|
|
|
+ return errors.New("read log path failed")
|
|
|
+ }
|
|
|
+ SerCfg.LogCfg.LogPath = log_path.SelectAttrValue("value", "./")
|
|
|
+
|
|
|
+ // 日志级别
|
|
|
+ log_level := setting.SelectElement("LogLevel")
|
|
|
+ if log_level == nil {
|
|
|
+ return errors.New("read log level failed")
|
|
|
+ }
|
|
|
+ ret, err := strconv.ParseUint(log_level.SelectAttrValue("value", "5"), 10, 32)
|
|
|
+ if err != nil {
|
|
|
+ return errors.New("read log level is invalid:")
|
|
|
+ }
|
|
|
+ SerCfg.LogCfg.LogLevel = int(ret)
|
|
|
}
|
|
|
|
|
|
// 数据库配置
|
|
|
@@ -178,8 +214,16 @@ func (c *ServiceConfig) Init(path string) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (c *ServiceConfig) GetWebListenPort() int {
|
|
|
- return SerCfg.WebCfg.ListenPort
|
|
|
+func (c *ServiceConfig) GetWebListenAddr() string {
|
|
|
+ return SerCfg.WebCfg.ListenAddr
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetDebugMode() bool {
|
|
|
+ return SerCfg.WebCfg.DebugMode
|
|
|
+}
|
|
|
+
|
|
|
+func (c *ServiceConfig) GetLogSetting() (string, int) {
|
|
|
+ return SerCfg.LogCfg.LogPath, SerCfg.LogCfg.LogLevel
|
|
|
}
|
|
|
|
|
|
func (c *ServiceConfig) GetDbDriver() string {
|