From 9d15b64300cd962b8c0135f751e43d755b1bf860 Mon Sep 17 00:00:00 2001 From: hellerve Date: Wed, 22 Feb 2017 18:49:17 +0100 Subject: [PATCH] added custom config, fix for #5 --- birdwatcher.go | 7 ++----- config.go | 9 +++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/birdwatcher.go b/birdwatcher.go index 901534b..fa93a86 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -98,16 +98,13 @@ func PrintServiceInfo(conf *Config, birdConf bird.BirdConfig) { func main() { bird6 := flag.Bool("6", false, "Use bird6 instead of bird") + configfile := flag.String("config", "./etc/ecix/birdwatcher.conf", "Configuration file location") flag.Parse() endpoints.VERSION = VERSION bird.InstallRateLimitReset() // Load configurations - conf, err := LoadConfigs([]string{ - "./etc/ecix/birdwatcher.conf", - "/etc/ecix/birdwatcher.conf", - "./etc/ecix/birdwatcher.local.conf", - }) + conf, err := LoadConfigs(ConfigOptions(*configfile)) if err != nil { log.Fatal("Loading birdwatcher configuration failed:", err) diff --git a/config.go b/config.go index 82660a9..7009bc7 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,7 @@ package main import ( "fmt" + "strings" "github.com/BurntSushi/toml" "github.com/imdario/mergo" @@ -54,3 +55,11 @@ func LoadConfigs(configFiles []string) (*Config, error) { return config, confError } + +func ConfigOptions(filename string) []string { + return []string{ + strings.Join([]string{"/", filename}, ""), + filename, + strings.Replace(filename, ".conf", ".local.conf", 1), + } +}