Embedded configuration
This commit is contained in:
parent
4558270c42
commit
7fcc4761da
3 changed files with 38 additions and 16 deletions
4
file.go
4
file.go
|
@ -36,10 +36,12 @@ func (provider *FileProvider) Provide(serviceChan chan<- *Service){
|
||||||
select {
|
select {
|
||||||
case event := <-watcher.Events:
|
case event := <-watcher.Events:
|
||||||
if(strings.Contains(event.Name,file.Name())){
|
if(strings.Contains(event.Name,file.Name())){
|
||||||
log.Println("event:", event)
|
log.Println("File event:", event)
|
||||||
service := provider.LoadFileConfig(file.Name())
|
service := provider.LoadFileConfig(file.Name())
|
||||||
|
if(service != nil) {
|
||||||
serviceChan <- service
|
serviceChan <- service
|
||||||
}
|
}
|
||||||
|
}
|
||||||
case error := <-watcher.Errors:
|
case error := <-watcher.Errors:
|
||||||
log.Println("error:", error)
|
log.Println("error:", error)
|
||||||
}
|
}
|
||||||
|
|
19
tortuous.go
19
tortuous.go
|
@ -31,15 +31,6 @@ var serviceChan = make(chan *Service)
|
||||||
var providers = []Provider{}
|
var providers = []Provider{}
|
||||||
|
|
||||||
func main() {
|
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)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
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() {
|
go func() {
|
||||||
for _, provider := range providers {
|
for _, provider := range providers {
|
||||||
provider.Provide(serviceChan)
|
provider.Provide(serviceChan)
|
||||||
|
|
|
@ -1,7 +1,26 @@
|
||||||
[docker]
|
#[docker]
|
||||||
endpoint = "unix:///var/run/docker.sock"
|
#endpoint = "unix:///var/run/docker.sock"
|
||||||
|
#watch = true
|
||||||
|
|
||||||
|
[file]
|
||||||
|
filename = "tortuous.toml"
|
||||||
watch = true
|
watch = true
|
||||||
|
|
||||||
#[file]
|
[backends]
|
||||||
#filename = "file.toml"
|
[backends.backend1]
|
||||||
#watch = true
|
[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"
|
Loading…
Reference in a new issue