From 7fcc4761dafdc70e13baa2e8c66f46bb12fcfedb Mon Sep 17 00:00:00 2001 From: emile Date: Mon, 7 Sep 2015 23:25:07 +0200 Subject: [PATCH] Embedded configuration --- file.go | 6 ++++-- tortuous.go | 19 ++++++++++--------- tortuous.toml | 29 ++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/file.go b/file.go index a5fc63d97..10bf91a4d 100644 --- a/file.go +++ b/file.go @@ -36,9 +36,11 @@ func (provider *FileProvider) Provide(serviceChan chan<- *Service){ select { case event := <-watcher.Events: if(strings.Contains(event.Name,file.Name())){ - log.Println("event:", event) + log.Println("File event:", event) service := provider.LoadFileConfig(file.Name()) - serviceChan <- service + if(service != nil) { + serviceChan <- service + } } case error := <-watcher.Errors: log.Println("error:", error) diff --git a/tortuous.go b/tortuous.go index 372f7bc6e..fdeebf552 100644 --- a/tortuous.go +++ b/tortuous.go @@ -31,15 +31,6 @@ var serviceChan = make(chan *Service) var providers = []Provider{} func main() { - configuration := LoadFileConfig() - if(configuration.Docker != nil){ - providers = append(providers, configuration.Docker) - } - - if(configuration.File != nil){ - providers = append(providers, configuration.File) - } - sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) @@ -65,6 +56,16 @@ func main() { } }() + configuration := LoadFileConfig() + log.Println("Configuration loaded", configuration) + if(configuration.Docker != nil){ + providers = append(providers, configuration.Docker) + } + + if(configuration.File != nil){ + providers = append(providers, configuration.File) + } + go func() { for _, provider := range providers { provider.Provide(serviceChan) diff --git a/tortuous.toml b/tortuous.toml index 24b7b1efd..3a86e2376 100644 --- a/tortuous.toml +++ b/tortuous.toml @@ -1,7 +1,26 @@ -[docker] -endpoint = "unix:///var/run/docker.sock" +#[docker] +#endpoint = "unix:///var/run/docker.sock" +#watch = true + +[file] +filename = "tortuous.toml" watch = true -#[file] -#filename = "file.toml" -#watch = true \ No newline at end of file +[backends] + [backends.backend1] + [backends.backend1.servers.server1] + url = "http://172.17.0.2:80" + [backends.backend1.servers.server2] + url = "http://172.17.0.3:80" + +[routes] + [routes.route1] + backends = ["backend1"] + [routes.route1.rules.test_zenika_1] + category = "Host" + value = "test.zenika.fr" + [routes.route2] + backends = ["backend1"] + [routes.route2.rules.test_zenika_2] + category = "Path" + value = "/test" \ No newline at end of file