X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxdsconfig%2Fconfig.go;h=854d383ff1b5fa19d4c45ebb3ce3b6e3374586e7;hb=09763a60f600342b8ecb997a83d80110f341048d;hp=1f53cbdae2198136f2d3f05aef36f3ec27401834;hpb=bfeab33538d50ee52750de4dd4c0e72b64f674f6;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go index 1f53cbd..854d383 100644 --- a/lib/xdsconfig/config.go +++ b/lib/xdsconfig/config.go @@ -7,6 +7,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" + common "github.com/iotbzh/xds-common/golib" ) // Config parameters (json format) of /config command @@ -16,20 +17,19 @@ type Config struct { VersionGitTag string `json:"gitTag"` // Private / un-exported fields - HTTPPort string `json:"-"` - FileConf *FileConfig - log *logrus.Logger + HTTPPort string `json:"-"` + FileConf *FileConfig `json:"-"` + Log *logrus.Logger `json:"-"` } // Config default values const ( DefaultAPIVersion = "1" - DefaultPort = "8010" DefaultLogLevel = "error" ) // Init loads the configuration on start-up -func Init(ctx *cli.Context, log *logrus.Logger) (Config, error) { +func Init(ctx *cli.Context, log *logrus.Logger) (*Config, error) { var err error // Define default configuration @@ -38,28 +38,33 @@ func Init(ctx *cli.Context, log *logrus.Logger) (Config, error) { APIVersion: DefaultAPIVersion, VersionGitTag: ctx.App.Metadata["git-tag"].(string), - HTTPPort: DefaultPort, - log: log, + HTTPPort: "8010", + FileConf: &FileConfig{ + LogsDir: "/tmp/logs", + SThgConf: &SyncThingConf{ + Home: "${HOME}/.xds/agent/syncthing-config", + }, + }, + Log: log, } // config file settings overwrite default config c.FileConf, err = updateConfigFromFile(&c, ctx.GlobalString("config")) if err != nil { - return Config{}, err + return nil, err } - return c, nil + if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) { + if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil { + return nil, fmt.Errorf("Cannot create logs dir: %v", err) + } + } + c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir) + + return &c, nil } // UpdateAll Update the current configuration func (c *Config) UpdateAll(newCfg Config) error { return fmt.Errorf("Not Supported") } - -func dirExists(path string) bool { - _, err := os.Stat(path) - if os.IsNotExist(err) { - return false - } - return true -}