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

@@ -138,13 +138,11 @@ func parseClientCommonCfg(fileType int, source []byte) (cfg config.ClientCommonC
if err != nil {
return
}
if cfg.LogFile == "console" {
cfg.LogWay = "console"
} else {
cfg.LogWay = "file"
}
err = cfg.Check()
cfg.Complete()
err = cfg.Validate()
if err != nil {
err = fmt.Errorf("Parse config error: %v", err)
return
}
return
@@ -185,21 +183,20 @@ func runClient(cfgFilePath string) (err error) {
var content []byte
content, err = config.GetRenderedConfFromFile(cfgFilePath)
if err != nil {
return
return err
}
cfg, err := parseClientCommonCfg(CfgFileTypeIni, content)
if err != nil {
return
return err
}
pxyCfgs, visitorCfgs, err := config.LoadAllProxyConfsFromIni(cfg.User, content, cfg.Start)
if err != nil {
return
return err
}
err = startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
return
return startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)
}
func startService(

View File

@@ -105,7 +105,6 @@ var rootCmd = &cobra.Command{
var cfg config.ServerCommonConf
var err error
if cfgFile != "" {
log.Info("frps uses config file: %s", cfgFile)
var content []byte
content, err = config.GetRenderedConfFromFile(cfgFile)
if err != nil {
@@ -113,7 +112,6 @@ var rootCmd = &cobra.Command{
}
cfg, err = parseServerCommonCfg(CfgFileTypeIni, content)
} else {
log.Info("frps uses command line arguments for config")
cfg, err = parseServerCommonCfg(CfgFileTypeCmd, nil)
}
if err != nil {
@@ -144,13 +142,10 @@ func parseServerCommonCfg(fileType int, source []byte) (cfg config.ServerCommonC
if err != nil {
return
}
if cfg.LogFile == "console" {
cfg.LogWay = "console"
} else {
cfg.LogWay = "file"
}
err = cfg.Check()
cfg.Complete()
err = cfg.Validate()
if err != nil {
err = fmt.Errorf("Parse config error: %v", err)
return
}
return
@@ -200,6 +195,13 @@ func parseServerCommonCfgFromCmd() (cfg config.ServerCommonConf, err error) {
func runServer(cfg config.ServerCommonConf) (err error) {
log.InitLog(cfg.LogWay, cfg.LogFile, cfg.LogLevel, cfg.LogMaxDays, cfg.DisableLogColor)
if cfgFile != "" {
log.Info("frps uses config file: %s", cfgFile)
} else {
log.Info("frps uses command line arguments for config")
}
svr, err := server.NewService(cfg)
if err != nil {
return err