优化连接处理逻辑,增加超时设置;重构命令读取与错误处理;新增公共工具函数以简化错误处理
This commit is contained in:
50
gateway/env/env.go
vendored
50
gateway/env/env.go
vendored
@@ -14,13 +14,16 @@ import (
|
||||
var (
|
||||
RunMode = "dev" // 运行模式,dev: 开发模式,prod: 生产模式
|
||||
|
||||
AppCtrlPort uint16 = 18080
|
||||
AppDataPort uint16 = 18081
|
||||
AppWebPort uint16 = 8848
|
||||
AppLogMode = "dev"
|
||||
AppExitTimeout = 5 // 等待服务停止的超时时间
|
||||
AppDataTimeout = 10 // 等待数据通道连接的超时时间
|
||||
AppUserTimeout = 10 // 等待用户发送数据的超时时间(端口复用需要分析协议,如果用户长期不发送数据,将会阻塞分析协程)
|
||||
AppCtrlPort uint16 = 18080
|
||||
AppDataPort uint16 = 18081
|
||||
AppWebPort uint16 = 8848
|
||||
AppLogMode = "dev"
|
||||
AppExitTimeout = 5 // 等待服务停止的超时时间
|
||||
AppDataTimeout = 10 // 等待数据通道连接的超时时间
|
||||
AppUserRWTimeout = 10 // 等待用户连接读写超时时间
|
||||
AppDataRWTimeout = 10 // 等待数据通道读写超时时间
|
||||
AppCtrlRWTimeout = 10 // 等待控制通道读写超时时间
|
||||
AppCtrlHBTimeout = 30 // 控制通道心跳超时时间(断开连接等待时间为:心跳等待时间 * 2 + 读写等待时间)
|
||||
|
||||
AuthWhitelist []net.IP // 全局白名单,可以将白名单 IP 视为一个可信任代理
|
||||
|
||||
@@ -103,13 +106,40 @@ func Init() {
|
||||
AppDataTimeout = appDataTimeout
|
||||
}
|
||||
|
||||
value = os.Getenv("APP_USER_TIMEOUT")
|
||||
value = os.Getenv("APP_USER_RW_TIMEOUT")
|
||||
if value != "" {
|
||||
appUserTimeout, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_USER_TIMEOUT 格式错误: %v", err))
|
||||
panic(fmt.Sprintf("环境变量 APP_USER_RW_TIMEOUT 格式错误: %v", err))
|
||||
}
|
||||
AppUserTimeout = appUserTimeout
|
||||
AppUserRWTimeout = appUserTimeout
|
||||
}
|
||||
|
||||
value = os.Getenv("APP_DATA_RW_TIMEOUT")
|
||||
if value != "" {
|
||||
appDataRWTimeout, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_DATA_RW_TIMEOUT 格式错误: %v", err))
|
||||
}
|
||||
AppDataRWTimeout = appDataRWTimeout
|
||||
}
|
||||
|
||||
value = os.Getenv("APP_CTRL_RW_TIMEOUT")
|
||||
if value != "" {
|
||||
appCtrlRWTimeout, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_CTRL_RW_TIMEOUT 格式错误: %v", err))
|
||||
}
|
||||
AppCtrlRWTimeout = appCtrlRWTimeout
|
||||
}
|
||||
|
||||
value = os.Getenv("APP_CTRL_HB_TIMEOUT")
|
||||
if value != "" {
|
||||
appCtrlHBTimeout, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("环境变量 APP_CTRL_HB_TIMEOUT 格式错误: %v", err))
|
||||
}
|
||||
AppCtrlHBTimeout = appCtrlHBTimeout
|
||||
}
|
||||
|
||||
value = os.Getenv("AUTH_WHITELIST")
|
||||
|
||||
Reference in New Issue
Block a user