Commit 4344557f authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Make some config parameters optional

Use default values for fetch_interval and reconnect_timeout
parent 15ba0e77
......@@ -54,6 +54,11 @@ type (
}
)
const (
defaultFetchInterval = 30 * time.Minute
defaultReconnectTimeout = 10 * time.Second
)
var (
client = &http.Client{}
app = kingpin.New(
......@@ -166,20 +171,31 @@ func getConfig(configFile string) (c config, err error) {
log.Fatalf("[Conf] No 'password' in config")
}
if c.FetchIntervalString == "" {
log.Fatalf("[Conf] No 'fetch_interval' in config")
}
if c.ReconnectTimeoutString == "" {
log.Fatalf("[Conf] No 'reconnect_timeout' in config")
c.FetchInterval = defaultFetchInterval
log.Printf("[Conf] Using default fetch_interval of %v", c.FetchInterval)
} else {
c.FetchInterval, err = time.ParseDuration(c.FetchIntervalString)
if err != nil {
log.Printf("[Conf] Error parsing fetch interval: %s", err)
err = nil
c.FetchInterval = defaultFetchInterval
log.Printf("[Conf] Using default fetch_interval of %v", c.FetchInterval)
}
}
// parse som of the config values
if c.FetchInterval, err = time.ParseDuration(c.FetchIntervalString); err != nil {
log.Printf("[Conf] Error parsing fetch interval: %s", err)
return
}
if c.ReconnectTimeout, err = time.ParseDuration(c.ReconnectTimeoutString); err != nil {
log.Printf("[Conf] Error parsing reconnect timeout: %s", err)
return
if c.ReconnectTimeoutString == "" {
c.ReconnectTimeout = defaultReconnectTimeout
log.Printf("[Conf] Using default reconnect_timeout of %v", c.ReconnectTimeout)
} else {
c.ReconnectTimeout, err = time.ParseDuration(c.ReconnectTimeoutString)
if err != nil {
log.Printf("[Conf] Error parsing reconnect timeout: %s", err)
err = nil
c.ReconnectTimeout = defaultReconnectTimeout
log.Printf("[Conf] Using default reconnect_timeout of %v", c.ReconnectTimeout)
}
}
// fetch the remote configuration
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment