fix_cfg_bug

This commit is contained in:
jcy 2016-04-13 17:44:14 +08:00
parent 2c39719cc0
commit a9398ada8f
2 changed files with 103 additions and 8 deletions

View File

@ -47,11 +47,23 @@ func LoadConf(confFile string) (err error) {
tmpStr, ok = conf.Get("common", "server_addr")
if ok {
ServerAddr = tmpStr
} else {
tmpStr, ok = conf.Get("common", "SERVER_ADDR")
if ok {
ServerAddr = tmpStr
}
}
tmpStr, ok = conf.Get("common", "server_port")
if ok {
ServerPort, _ = strconv.ParseInt(tmpStr, 10, 64)
} else {
tmpStr, ok = conf.Get("common", "SERVER_PORT")
if ok {
ServerPort, _ = strconv.ParseInt(tmpStr, 10, 64)
}
}
tmpStr, ok = conf.Get("common", "log_file")
@ -62,20 +74,43 @@ func LoadConf(confFile string) (err error) {
} else {
LogWay = "file"
}
} else {
tmpStr, ok = conf.Get("common", "LOG_FILE")
if ok {
LogFile = tmpStr
if LogFile == "console" {
LogWay = "console"
} else {
LogWay = "file"
}
}
}
tmpStr, ok = conf.Get("common", "log_level")
if ok {
LogLevel = tmpStr
} else {
tmpStr, ok = conf.Get("common", "LOG_LEVEL")
if ok {
LogLevel = tmpStr
}
}
var authToken string
tmpStr, ok = conf.Get("common", "auth_token")
if ok {
authToken = tmpStr
} else {
tmpStr, ok = conf.Get("common", "AUTH_TOKEN")
if ok {
authToken = tmpStr
} else {
return fmt.Errorf("auth_token not found")
}
}
// proxies
for name, section := range conf {
@ -89,13 +124,25 @@ func LoadConf(confFile string) (err error) {
// local_ip
proxyClient.LocalIp, ok = section["local_ip"]
if !ok {
proxyClient.LocalIp, ok = section["LOCAL_IP"]
if !ok {
// use 127.0.0.1 as default
proxyClient.LocalIp = "127.0.0.1"
}
}
// local_port
portStr, ok := section["local_port"]
if ok {
proxyClient.LocalPort, err = strconv.ParseInt(portStr, 10, 64)
if err != nil {
return fmt.Errorf("Parse ini file error: proxy [%s] local_port error", proxyClient.Name)
}
} else {
portStr, ok := section["LOCAL_PORT"]
if ok {
proxyClient.LocalPort, err = strconv.ParseInt(portStr, 10, 64)
if err != nil {
@ -104,14 +151,19 @@ func LoadConf(confFile string) (err error) {
} else {
return fmt.Errorf("Parse ini file error: proxy [%s] local_port not found", proxyClient.Name)
}
}
// use_encryption
proxyClient.UseEncryption = false
useEncryptionStr, ok := section["use_encryption"]
if ok && useEncryptionStr == "true" {
proxyClient.UseEncryption = true
} else {
useEncryptionStr, ok := section["USE_ENCRYPTION"]
if ok && useEncryptionStr == "true" {
proxyClient.UseEncryption = true
}
}
ProxyClients[proxyClient.Name] = proxyClient
}
}

View File

@ -47,11 +47,23 @@ func LoadConf(confFile string) (err error) {
tmpStr, ok = conf.Get("common", "bind_addr")
if ok {
BindAddr = tmpStr
} else {
tmpStr, ok = conf.Get("common", "BIND_ADDR")
if ok {
BindAddr = tmpStr
}
}
tmpStr, ok = conf.Get("common", "bind_port")
if ok {
BindPort, _ = strconv.ParseInt(tmpStr, 10, 64)
} else {
tmpStr, ok = conf.Get("common", "BIND_PORT")
if ok {
BindPort, _ = strconv.ParseInt(tmpStr, 10, 64)
}
}
tmpStr, ok = conf.Get("common", "log_file")
@ -62,11 +74,28 @@ func LoadConf(confFile string) (err error) {
} else {
LogWay = "file"
}
} else {
tmpStr, ok = conf.Get("common", "LOG_FILE")
if ok {
LogFile = tmpStr
if LogFile == "console" {
LogWay = "console"
} else {
LogWay = "file"
}
}
}
tmpStr, ok = conf.Get("common", "log_level")
if ok {
LogLevel = tmpStr
} else {
tmpStr, ok = conf.Get("common", "LOG_LEVEL")
if ok {
LogLevel = tmpStr
}
}
// servers
@ -76,16 +105,29 @@ func LoadConf(confFile string) (err error) {
proxyServer.Name = name
proxyServer.AuthToken, ok = section["auth_token"]
if !ok {
proxyServer.AuthToken, ok = section["AUTH_TOKEN"]
if !ok {
return fmt.Errorf("Parse ini file error: proxy [%s] no auth_token found", proxyServer.Name)
}
}
proxyServer.BindAddr, ok = section["bind_addr"]
if !ok {
proxyServer.BindAddr, ok = section["BIND_ADDR"]
if !ok {
proxyServer.BindAddr = "0.0.0.0"
}
}
portStr, ok := section["listen_port"]
if ok {
proxyServer.ListenPort, err = strconv.ParseInt(portStr, 10, 64)
if err != nil {
return fmt.Errorf("Parse ini file error: proxy [%s] listen_port error", proxyServer.Name)
}
} else {
portStr, ok := section["LISTEN_PORT"]
if ok {
proxyServer.ListenPort, err = strconv.ParseInt(portStr, 10, 64)
if err != nil {
@ -94,6 +136,7 @@ func LoadConf(confFile string) (err error) {
} else {
return fmt.Errorf("Parse ini file error: proxy [%s] listen_port not found", proxyServer.Name)
}
}
proxyServer.Init()
ProxyServers[proxyServer.Name] = proxyServer