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 {
|
||||
glog.Fatalf("[Config] unable to read config: %v", err)
|
||||
}
|
||||
StartAllRoutes()
|
||||
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
||||
glog.Fatalf("[Config] file renamed / deleted")
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ func (p *Provider) grWatchDockerChanges() {
|
|||
// TODO: handle actor only
|
||||
p.Logf("Event", "container %s %s caused rebuild", msg.Actor.Attributes["name"], msg.Action)
|
||||
p.StopAllRoutes()
|
||||
p.BuildStartRoutes()
|
||||
p.StartAllRoutes()
|
||||
case err := <-errChan:
|
||||
p.Logf("Event", "error %s", err)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
|
|
@ -64,7 +64,7 @@ func (p *Provider) grWatchFileChanges() {
|
|||
case event.Has(fsnotify.Write):
|
||||
p.Logf("Watcher", "file change detected")
|
||||
p.StopAllRoutes()
|
||||
p.BuildStartRoutes()
|
||||
p.StartAllRoutes()
|
||||
case event.Has(fsnotify.Remove), event.Has(fsnotify.Rename):
|
||||
p.Logf("Watcher", "file renamed / deleted")
|
||||
p.StopAllRoutes()
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"flag"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
@ -12,7 +11,6 @@ import (
|
|||
|
||||
func main() {
|
||||
var err error
|
||||
var wg sync.WaitGroup
|
||||
|
||||
flag.Parse()
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -27,15 +25,7 @@ func main() {
|
|||
glog.Fatal("unable to read config: ", err)
|
||||
}
|
||||
|
||||
wg.Add(len(config.Providers))
|
||||
for _, p := range config.Providers {
|
||||
go func(p *Provider) {
|
||||
p.BuildStartRoutes()
|
||||
wg.Done()
|
||||
}(p)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
StartAllRoutes()
|
||||
go ListenConfigChanges()
|
||||
|
||||
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() {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
|
@ -59,7 +71,7 @@ func (p *Provider) StopAllRoutes() {
|
|||
p.routes = make(map[string]Route)
|
||||
}
|
||||
|
||||
func (p *Provider) BuildStartRoutes() {
|
||||
func (p *Provider) StartAllRoutes() {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue