X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsconfig%2Ffileconfig.go;h=5cf8db2df53d82c178fffdb291a7c8f536b993ad;hb=a50baa7c309f7eb55fe87c71f4c688ace325b6ac;hp=0c4828ccef8be17fae566021f7f839974f91d1ac;hpb=bfeab33538d50ee52750de4dd4c0e72b64f674f6;p=src%2Fxds%2Fxds-agent.git 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 -}