Reconstruct config (#2098)

* refactoring config

* Update by comments
This commit is contained in:
yuyulei
2021-01-26 11:31:08 +08:00
committed by GitHub
parent a821db3f45
commit 3621aad1c1
31 changed files with 2798 additions and 1690 deletions

View File

@@ -129,9 +129,9 @@ func handleSignal(svr *client.Service) {
close(kcpDoneCh)
}
func parseClientCommonCfg(fileType int, content string) (cfg config.ClientCommonConf, err error) {
func parseClientCommonCfg(fileType int, source []byte) (cfg config.ClientCommonConf, err error) {
if fileType == CfgFileTypeIni {
cfg, err = parseClientCommonCfgFromIni(content)
cfg, err = config.UnmarshalClientConfFromIni(source)
} else if fileType == CfgFileTypeCmd {
cfg, err = parseClientCommonCfgFromCmd()
}
@@ -146,14 +146,6 @@ func parseClientCommonCfg(fileType int, content string) (cfg config.ClientCommon
return
}
func parseClientCommonCfgFromIni(content string) (config.ClientCommonConf, error) {
cfg, err := config.UnmarshalClientConfFromIni(content)
if err != nil {
return config.ClientCommonConf{}, err
}
return cfg, err
}
func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
cfg = config.GetDefaultClientConf()
@@ -191,7 +183,7 @@ func parseClientCommonCfgFromCmd() (cfg config.ClientCommonConf, err error) {
}
func runClient(cfgFilePath string) (err error) {
var content string
var content []byte
content, err = config.GetRenderedConfFromFile(cfgFilePath)
if err != nil {
return
@@ -202,9 +194,9 @@ func runClient(cfgFilePath string) (err error) {
return
}
pxyCfgs, visitorCfgs, err := config.LoadAllConfFromIni(cfg.User, content, cfg.Start)
pxyCfgs, visitorCfgs, err := config.LoadAllProxyConfsFromIni(cfg.User, content, cfg.Start)
if err != nil {
return err
return
}
err = startService(cfg, pxyCfgs, visitorCfgs, cfgFilePath)