diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-05-18 11:04:44 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-05-18 11:04:44 +0200 |
commit | ca0326f03972b9adf5a5ee21a963c7ef8a5ad366 (patch) | |
tree | 3e8efc249a8bc35bfa4affdfa6eca73dcb838194 /lib/xdsconfig/fileconfig.go | |
parent | 2c9ae6a5a27ae2f2e23495c613e7a53aed8e786c (diff) |
Improved ResolveEnvVar and add support of tilde (~/...)
Diffstat (limited to 'lib/xdsconfig/fileconfig.go')
-rw-r--r-- | lib/xdsconfig/fileconfig.go | 25 |
1 files changed, 2 insertions, 23 deletions
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index d39cae0..4be54ff 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -2,12 +2,10 @@ package xdsconfig import ( "encoding/json" - "fmt" "os" "os/user" "path" "path/filepath" - "regexp" "strings" "github.com/iotbzh/xds-server/lib/common" @@ -89,11 +87,10 @@ func updateConfigFromFile(c *Config, confFile string) error { &fCfg.SThgConf.Home, &fCfg.SThgConf.BinDir} { - rep, err := resolveEnvVar(*field) - if err != nil { + var err error + if *field, err = common.ResolveEnvVar(*field); err != nil { return err } - *field = path.Clean(rep) } // Config file settings overwrite default config @@ -123,21 +120,3 @@ func updateConfigFromFile(c *Config, confFile string) error { return nil } - -// resolveEnvVar Resolved environment variable regarding the syntax ${MYVAR} -func resolveEnvVar(s string) (string, error) { - re := regexp.MustCompile("\\${(.*)}") - vars := re.FindAllStringSubmatch(s, -1) - res := s - for _, v := range vars { - val := os.Getenv(v[1]) - if val == "" { - return res, fmt.Errorf("ERROR: %s env variable not defined", v[1]) - } - - rer := regexp.MustCompile("\\${" + v[1] + "}") - res = rer.ReplaceAllString(res, val) - } - - return res, nil -} |