Use a better method to reload command presets

This commit is contained in:
NI
2020-03-12 21:18:08 +08:00
parent b2210ce2b6
commit 1009cd4284
12 changed files with 206 additions and 374 deletions

View File

@@ -135,10 +135,7 @@ func (f fileCfgCommon) build() (fileCfgCommon, error) {
}, nil
}
func loadFile(
filePath string,
r Reconfigurator,
) (string, Configuration, error) {
func loadFile(filePath string) (string, Configuration, error) {
f, fErr := os.Open(filePath)
if fErr != nil {
@@ -174,7 +171,7 @@ func loadFile(
presets[i] = finalCfg.Presets[i].build()
}
return fileTypeName, r(Configuration{
return fileTypeName, Configuration{
HostName: finalCfg.HostName,
SharedKey: finalCfg.SharedKey,
DialTimeout: time.Duration(finalCfg.DialTimeout) *
@@ -185,19 +182,16 @@ func loadFile(
Servers: servers,
Presets: presets,
OnlyAllowPresetRemotes: cfg.OnlyAllowPresetRemotes,
}), nil
}, nil
}
// File creates a configuration file loader
func File(customPath string) Loader {
return func(
log log.Logger,
r Reconfigurator,
) (string, Configuration, error) {
return func(log log.Logger) (string, Configuration, error) {
if len(customPath) > 0 {
log.Info("Loading configuration from: %s", customPath)
return loadFile(customPath, r)
return loadFile(customPath)
}
log.Info("Loading configuration from one of the default " +
@@ -239,7 +233,7 @@ func File(customPath string) Loader {
log.Info("Configuration file \"%s\" has been selected",
fallbackFileSearchList[f])
return loadFile(fallbackFileSearchList[f], r)
return loadFile(fallbackFileSearchList[f])
}
return fileTypeName, Configuration{}, fmt.Errorf(