summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/fileconfig.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xdsconfig/fileconfig.go')
-rw-r--r--lib/xdsconfig/fileconfig.go37
1 files changed, 15 insertions, 22 deletions
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 0c4828c..5cf8db2 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -19,6 +19,7 @@ type SyncThingConf struct {
type FileConfig struct {
HTTPPort string `json:"httpPort"`
+ LogsDir string `json:"logsDir"`
SThgConf *SyncThingConf `json:"syncthing"`
}
@@ -60,7 +61,7 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) {
return &fCfg, nil
}
- c.log.Infof("Use config file: %s", *cFile)
+ c.Log.Infof("Use config file: %s", *cFile)
// TODO move on viper package to support comments in JSON and also
// bind with flags (command line options)
@@ -73,18 +74,22 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) {
}
// Support environment variables (IOW ${MY_ENV_VAR} syntax) in agent-config.json
- // TODO: better to use reflect package to iterate on fields and be more generic
- var rep string
-
- if rep, err = resolveEnvVar(fCfg.SThgConf.BinDir); err != nil {
- return nil, err
+ for _, field := range []*string{
+ &fCfg.LogsDir,
+ &fCfg.SThgConf.Home,
+ &fCfg.SThgConf.BinDir} {
+
+ rep, err := resolveEnvVar(*field)
+ if err != nil {
+ return nil, err
+ }
+ *field = path.Clean(rep)
}
- fCfg.SThgConf.BinDir = path.Clean(rep)
- if rep, err = resolveEnvVar(fCfg.SThgConf.Home); err != nil {
- return nil, err
+ // Config file settings overwrite default config
+ if fCfg.HTTPPort != "" {
+ c.HTTPPort = fCfg.HTTPPort
}
- fCfg.SThgConf.Home = path.Clean(rep)
return &fCfg, nil
}
@@ -106,15 +111,3 @@ func resolveEnvVar(s string) (string, error) {
return res, nil
}
-
-// exists returns whether the given file or directory exists or not
-func exists(path string) bool {
- _, err := os.Stat(path)
- if err == nil {
- return true
- }
- if os.IsNotExist(err) {
- return false
- }
- return true
-}