8 "github.com/Sirupsen/logrus"
9 "github.com/codegangsta/cli"
10 "github.com/iotbzh/xds-agent/lib/common"
13 // Config parameters (json format) of /config command
15 Version string `json:"version"`
16 APIVersion string `json:"apiVersion"`
17 VersionGitTag string `json:"gitTag"`
19 // Private / un-exported fields
20 HTTPPort string `json:"-"`
21 FileConf *FileConfig `json:"-"`
22 Log *logrus.Logger `json:"-"`
25 // Config default values
27 DefaultAPIVersion = "1"
29 DefaultLogLevel = "error"
32 // Init loads the configuration on start-up
33 func Init(ctx *cli.Context, log *logrus.Logger) (*Config, error) {
36 // Define default configuration
38 Version: ctx.App.Metadata["version"].(string),
39 APIVersion: DefaultAPIVersion,
40 VersionGitTag: ctx.App.Metadata["git-tag"].(string),
42 HTTPPort: DefaultPort,
46 // config file settings overwrite default config
47 c.FileConf, err = updateConfigFromFile(&c, ctx.GlobalString("config"))
52 if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
53 if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
54 return nil, fmt.Errorf("Cannot create logs dir: %v", err)
57 c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
62 // UpdateAll Update the current configuration
63 func (c *Config) UpdateAll(newCfg Config) error {
64 return fmt.Errorf("Not Supported")