mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 08:48:32 +02:00
docker: clear routes on docker disconnect, reload routes on connection restore
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/yusing/go-proxy/internal/route/provider/types"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
"github.com/yusing/go-proxy/internal/watcher"
|
||||
eventsPkg "github.com/yusing/go-proxy/internal/watcher/events"
|
||||
)
|
||||
|
||||
type EventHandler struct {
|
||||
@@ -29,10 +30,19 @@ func (p *Provider) newEventHandler() *EventHandler {
|
||||
|
||||
func (handler *EventHandler) Handle(parent task.Parent, events []watcher.Event) {
|
||||
oldRoutes := handler.provider.routes
|
||||
|
||||
isForceReload := false
|
||||
for _, event := range events {
|
||||
if event.Action == eventsPkg.ActionForceReload {
|
||||
isForceReload = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
newRoutes, err := handler.provider.loadRoutes()
|
||||
if err != nil {
|
||||
handler.errs.Add(err)
|
||||
if len(newRoutes) == 0 {
|
||||
if len(newRoutes) == 0 && !isForceReload {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user