diff --git a/bird/bird.go b/bird/bird.go index b737344..85a9d6a 100644 --- a/bird/bird.go +++ b/bird/bird.go @@ -7,7 +7,7 @@ import ( "time" ) -var BirdCmd string +var Conf BirdConfig var Cache = struct { sync.RWMutex @@ -31,7 +31,7 @@ func toCache(key string, val Parsed) { func Run(args string) ([]byte, error) { args = "show " + args argsList := strings.Split(args, " ") - return exec.Command(BirdCmd, argsList...).Output() + return exec.Command(Conf.BirdCmd, argsList...).Output() } func RunAndParse(cmd string, parser func([]byte) Parsed) (Parsed, bool) { diff --git a/bird/config.go b/bird/config.go new file mode 100644 index 0000000..c84802b --- /dev/null +++ b/bird/config.go @@ -0,0 +1,16 @@ +package bird + +// Birdwatcher Birdc Configuration + +type StatusConfig struct { + ReconfigTimestampSource string `toml:"reconfig_timestamp_source"` + ReconfigTimestampMatch string `toml:"reconfig_timestamp_match"` + + FilteredFields []string `toml:"filtered_fields"` +} + +type BirdConfig struct { + Listen string + ConfigFilename string `toml:"config"` + BirdCmd string `toml:"birdc"` +} diff --git a/birdwatcher.go b/birdwatcher.go index 339fb1b..e5a9621 100644 --- a/birdwatcher.go +++ b/birdwatcher.go @@ -7,6 +7,7 @@ import ( "github.com/ecix/birdwatcher/bird" "github.com/ecix/birdwatcher/endpoints" + "github.com/julienschmidt/httprouter" ) @@ -29,7 +30,7 @@ func makeRouter() *httprouter.Router { // Print service information like, listen address, // access restrictions and configuration flags -func PrintServiceInfo(conf *Config, birdConf BirdConfig) { +func PrintServiceInfo(conf *Config, birdConf bird.BirdConfig) { // General Info log.Println("Starting Birdwatcher") log.Println(" Using:", birdConf.BirdCmd) @@ -60,7 +61,7 @@ func main() { PrintServiceInfo(conf, birdConf) // Configure client - bird.BirdCmd = birdConf.BirdCmd + bird.Conf = birdConf // Make server r := makeRouter() diff --git a/config.go b/config.go index fea2b6f..d8a82b4 100644 --- a/config.go +++ b/config.go @@ -6,32 +6,22 @@ import ( "fmt" "github.com/BurntSushi/toml" "github.com/imdario/mergo" + + "github.com/ecix/birdwatcher/bird" ) type Config struct { Server ServerConfig - Status StatusConfig - Bird BirdConfig - Bird6 BirdConfig + + Status bird.StatusConfig + Bird bird.BirdConfig + Bird6 bird.BirdConfig } type ServerConfig struct { AllowFrom []string `toml:"allow_from"` } -type StatusConfig struct { - ReconfigTimestampSource string `toml:"reconfig_timestamp_source"` - ReconfigTimestampMatch string `toml:"reconfig_timestamp_match"` - - FilteredFields []string `toml:"filtered_fields"` -} - -type BirdConfig struct { - Listen string - ConfigFilename string `toml:"config"` - BirdCmd string `toml:"birdc"` -} - // Try to load configfiles as specified in the files // list. For example: //