8 "github.com/Sirupsen/logrus"
9 "github.com/codegangsta/cli"
10 common "github.com/iotbzh/xds-common/golib"
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"
28 DefaultLogLevel = "error"
31 // Init loads the configuration on start-up
32 func Init(ctx *cli.Context, log *logrus.Logger) (*Config, error) {
35 // Define default configuration
37 Version: ctx.App.Metadata["version"].(string),
38 APIVersion: DefaultAPIVersion,
39 VersionGitTag: ctx.App.Metadata["git-tag"].(string),
42 FileConf: &FileConfig{
44 SThgConf: &SyncThingConf{
45 Home: "${HOME}/.xds/agent/syncthing-config",
51 // config file settings overwrite default config
52 c.FileConf, err = updateConfigFromFile(&c, ctx.GlobalString("config"))
57 if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
58 if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
59 return nil, fmt.Errorf("Cannot create logs dir: %v", err)
62 c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
67 // UpdateAll Update the current configuration
68 func (c *Config) UpdateAll(newCfg Config) error {
69 return fmt.Errorf("Not Supported")