mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fix output and config reload
This commit is contained in:
parent
e14eeb914f
commit
eee6ff4f15
6 changed files with 17 additions and 14 deletions
BIN
bin/go-proxy
BIN
bin/go-proxy
Binary file not shown.
|
@ -64,6 +64,7 @@ func ListenConfigChanges() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("[Config] unable to read config: %v", err)
|
glog.Fatalf("[Config] unable to read config: %v", err)
|
||||||
}
|
}
|
||||||
|
StartAllRoutes()
|
||||||
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
||||||
glog.Fatalf("[Config] file renamed / deleted")
|
glog.Fatalf("[Config] file renamed / deleted")
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ func (p *Provider) grWatchDockerChanges() {
|
||||||
// TODO: handle actor only
|
// TODO: handle actor only
|
||||||
p.Logf("Event", "container %s %s caused rebuild", msg.Actor.Attributes["name"], msg.Action)
|
p.Logf("Event", "container %s %s caused rebuild", msg.Actor.Attributes["name"], msg.Action)
|
||||||
p.StopAllRoutes()
|
p.StopAllRoutes()
|
||||||
p.BuildStartRoutes()
|
p.StartAllRoutes()
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
p.Logf("Event", "error %s", err)
|
p.Logf("Event", "error %s", err)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (p *Provider) grWatchFileChanges() {
|
||||||
case event.Has(fsnotify.Write):
|
case event.Has(fsnotify.Write):
|
||||||
p.Logf("Watcher", "file change detected")
|
p.Logf("Watcher", "file change detected")
|
||||||
p.StopAllRoutes()
|
p.StopAllRoutes()
|
||||||
p.BuildStartRoutes()
|
p.StartAllRoutes()
|
||||||
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
||||||
p.Logf("Watcher", "file renamed / deleted")
|
p.Logf("Watcher", "file renamed / deleted")
|
||||||
p.StopAllRoutes()
|
p.StopAllRoutes()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
@ -12,7 +11,6 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
var wg sync.WaitGroup
|
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
@ -27,15 +25,7 @@ func main() {
|
||||||
glog.Fatal("unable to read config: ", err)
|
glog.Fatal("unable to read config: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Add(len(config.Providers))
|
StartAllRoutes()
|
||||||
for _, p := range config.Providers {
|
|
||||||
go func(p *Provider) {
|
|
||||||
p.BuildStartRoutes()
|
|
||||||
wg.Done()
|
|
||||||
}(p)
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
go ListenConfigChanges()
|
go ListenConfigChanges()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
|
@ -31,6 +31,18 @@ func (p *Provider) GetProxyConfigs() ([]*ProxyConfig, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartAllRoutes() {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(len(config.Providers))
|
||||||
|
for _, p := range config.Providers {
|
||||||
|
go func(p *Provider) {
|
||||||
|
p.StartAllRoutes()
|
||||||
|
wg.Done()
|
||||||
|
}(p)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Provider) StopAllRoutes() {
|
func (p *Provider) StopAllRoutes() {
|
||||||
p.mutex.Lock()
|
p.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.mutex.Unlock()
|
||||||
|
@ -59,7 +71,7 @@ func (p *Provider) StopAllRoutes() {
|
||||||
p.routes = make(map[string]Route)
|
p.routes = make(map[string]Route)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) BuildStartRoutes() {
|
func (p *Provider) StartAllRoutes() {
|
||||||
p.mutex.Lock()
|
p.mutex.Lock()
|
||||||
defer p.mutex.Unlock()
|
defer p.mutex.Unlock()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue