fix config parse logic (#2323)

This commit is contained in:
fatedier
2021-03-22 14:53:30 +08:00
committed by GitHub
parent 6b80861bd6
commit 9a849a29e9
12 changed files with 70 additions and 42 deletions

View File

@ -173,13 +173,21 @@ func GetDefaultClientConf() ClientCommonConf {
}
}
func (cfg *ClientCommonConf) Check() error {
func (cfg *ClientCommonConf) Complete() {
if cfg.LogFile == "console" {
cfg.LogWay = "console"
} else {
cfg.LogWay = "file"
}
}
func (cfg *ClientCommonConf) Validate() error {
if cfg.HeartbeatInterval <= 0 {
return fmt.Errorf("Parse conf error: invalid heartbeat_interval")
return fmt.Errorf("invalid heartbeat_interval")
}
if cfg.HeartbeatTimeout < cfg.HeartbeatInterval {
return fmt.Errorf("Parse conf error: invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
return fmt.Errorf("invalid heartbeat_timeout, heartbeat_timeout is less than heartbeat_interval")
}
if cfg.TLSEnable == false {
@ -196,6 +204,10 @@ func (cfg *ClientCommonConf) Check() error {
}
}
if cfg.Protocol != "tcp" && cfg.Protocol != "kcp" && cfg.Protocol != "websocket" {
return fmt.Errorf("invalid protocol")
}
return nil
}