summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/fileconfig.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 17:10:45 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-17 17:10:45 +0200
commita50baa7c309f7eb55fe87c71f4c688ace325b6ac (patch)
tree14ed08e3abad729bce718bfbd596eb62d1676675 /lib/xdsconfig/fileconfig.go
parent59784289d1d0296e470c46dc279aa3576c60801e (diff)
Add logsDir setting and more
- add logsDir setting in config.json - redirect Syncthing and Syncthing-inotify into log files - Use autogenerated Syncthing apikey if gui-apikey not set in config.json
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
-}