Embedded configuration

This commit is contained in:
emile 2015-09-07 23:25:07 +02:00
parent 4558270c42
commit 7fcc4761da
3 changed files with 38 additions and 16 deletions

View file

@ -36,10 +36,12 @@ 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())
if(service != nil) {
serviceChan <- service
}
}
case error := <-watcher.Errors:
log.Println("error:", error)
}

View file

@ -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)

View file

@ -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
[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"