diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-06-20 22:29:59 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-06-20 22:29:59 +0200 |
commit | 8f41ac456fc92a9ec333579498e9933d73404905 (patch) | |
tree | 6be8211c41c7ff19a6b23bd1d1d289a39bd6373e /lib/xdsconfig | |
parent | dd62e1e5ec325c77164c578d11ba4c0e118307d9 (diff) |
Remove duplicate fields and set default SDK dir.
- Removed duplicate fields between Config and FileConfig
- set /xdt/sdk as default SDK directory
Diffstat (limited to 'lib/xdsconfig')
-rw-r--r-- | lib/xdsconfig/config.go | 26 | ||||
-rw-r--r-- | lib/xdsconfig/fileconfig.go | 36 |
2 files changed, 32 insertions, 30 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go index 465620b..5ada35f 100644 --- a/lib/xdsconfig/config.go +++ b/lib/xdsconfig/config.go @@ -19,11 +19,8 @@ type Config struct { Folders FoldersConfig `json:"folders"` // Private (un-exported fields in REST GET /config route) - FileConf FileConfig `json:"-"` - WebAppDir string `json:"-"` - HTTPPort string `json:"-"` - ShareRootDir string `json:"-"` - Log *logrus.Logger `json:"-"` + FileConf FileConfig `json:"-"` + Log *logrus.Logger `json:"-"` } // Config default values @@ -31,6 +28,7 @@ const ( DefaultAPIVersion = "1" DefaultPort = "8000" DefaultShareDir = "/mnt/share" + DefaultSdkRootDir = "/xdt/sdk" ) // Init loads the configuration on start-up @@ -44,11 +42,13 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) { VersionGitTag: cliCtx.App.Metadata["git-tag"].(string), Builder: BuilderConfig{}, Folders: FoldersConfig{}, - - WebAppDir: "webapp/dist", - HTTPPort: DefaultPort, - ShareRootDir: DefaultShareDir, - Log: log, + FileConf: FileConfig{ + WebAppDir: "webapp/dist", + ShareRootDir: DefaultShareDir, + SdkRootDir: DefaultSdkRootDir, + HTTPPort: DefaultPort, + }, + Log: log, } // config file settings overwrite default config @@ -58,12 +58,12 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) { } // Update location of shared dir if needed - if !common.Exists(c.ShareRootDir) { - if err := os.MkdirAll(c.ShareRootDir, 0770); err != nil { + if !common.Exists(c.FileConf.ShareRootDir) { + if err := os.MkdirAll(c.FileConf.ShareRootDir, 0770); err != nil { return nil, fmt.Errorf("No valid shared directory found: %v", err) } } - c.Log.Infoln("Share root directory: ", c.ShareRootDir) + c.Log.Infoln("Share root directory: ", c.FileConf.ShareRootDir) if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) { if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil { diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go index 01bd4c9..99e5382 100644 --- a/lib/xdsconfig/fileconfig.go +++ b/lib/xdsconfig/fileconfig.go @@ -77,7 +77,6 @@ func updateConfigFromFile(c *Config, confFile string) error { if err := json.NewDecoder(fd).Decode(&fCfg); err != nil { return err } - c.FileConf = fCfg // Support environment variables (IOW ${MY_ENV_VAR} syntax) in config.json for _, field := range []*string{ @@ -94,30 +93,33 @@ func updateConfigFromFile(c *Config, confFile string) error { } } - // Config file settings overwrite default config - - if fCfg.WebAppDir != "" { - c.WebAppDir = strings.Trim(fCfg.WebAppDir, " ") + // Use config file settings else use default config + if fCfg.WebAppDir == "" { + fCfg.WebAppDir = c.FileConf.WebAppDir + } + if fCfg.ShareRootDir == "" { + fCfg.ShareRootDir = c.FileConf.ShareRootDir } - // Is it a full path ? - if !strings.HasPrefix(c.WebAppDir, "/") && exePath != "" { + if fCfg.SdkRootDir == "" { + fCfg.SdkRootDir = c.FileConf.SdkRootDir + } + if fCfg.HTTPPort == "" { + fCfg.HTTPPort = c.FileConf.HTTPPort + } + + // Resolve webapp dir (support relative or full path) + fCfg.WebAppDir = strings.Trim(fCfg.WebAppDir, " ") + if !strings.HasPrefix(fCfg.WebAppDir, "/") && exePath != "" { // Check first from current directory for _, rootD := range []string{cwd, exePath} { - ff := path.Join(rootD, c.WebAppDir, "index.html") + ff := path.Join(rootD, fCfg.WebAppDir, "index.html") if common.Exists(ff) { - c.WebAppDir = path.Join(rootD, c.WebAppDir) + fCfg.WebAppDir = path.Join(rootD, fCfg.WebAppDir) break } } } - if fCfg.ShareRootDir != "" { - c.ShareRootDir = fCfg.ShareRootDir - } - - if fCfg.HTTPPort != "" { - c.HTTPPort = fCfg.HTTPPort - } - + c.FileConf = fCfg return nil } |