diff --git a/internal/idlewatcher/provider/proxmox.go b/internal/idlewatcher/provider/proxmox.go index f42cd11a..0ef6131f 100644 --- a/internal/idlewatcher/provider/proxmox.go +++ b/internal/idlewatcher/provider/proxmox.go @@ -11,7 +11,7 @@ import ( "github.com/yusing/godoxy/internal/proxmox" "github.com/yusing/godoxy/internal/types" "github.com/yusing/godoxy/internal/watcher" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" gperr "github.com/yusing/goutils/errs" ) @@ -101,7 +101,7 @@ func (p *ProxmoxProvider) Watch(ctx context.Context) (<-chan watcher.Event, <-ch defer ticker.Stop() event := watcher.Event{ - Type: events.EventTypeDocker, + Type: watcherEvents.EventTypeDocker, ActorID: strconv.FormatUint(p.vmid, 10), ActorName: p.lxcName, } @@ -119,9 +119,9 @@ func (p *ProxmoxProvider) Watch(ctx context.Context) (<-chan watcher.Event, <-ch if p.running != running { p.running = running if running { - event.Action = events.ActionContainerStart + event.Action = watcherEvents.ActionContainerStart } else { - event.Action = events.ActionContainerStop + event.Action = watcherEvents.ActionContainerStop } eventCh <- event } diff --git a/internal/idlewatcher/types/provider.go b/internal/idlewatcher/types/provider.go index 9806c24b..135e5700 100644 --- a/internal/idlewatcher/types/provider.go +++ b/internal/idlewatcher/types/provider.go @@ -4,7 +4,7 @@ import ( "context" "github.com/yusing/godoxy/internal/types" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" ) type Provider interface { @@ -14,6 +14,6 @@ type Provider interface { ContainerStop(ctx context.Context, signal types.ContainerSignal, timeout int) error ContainerKill(ctx context.Context, signal types.ContainerSignal) error ContainerStatus(ctx context.Context) (ContainerStatus, error) - Watch(ctx context.Context) (eventCh <-chan events.Event, errCh <-chan error) + Watch(ctx context.Context) (eventCh <-chan watcherEvents.Event, errCh <-chan error) Close() } diff --git a/internal/idlewatcher/watcher.go b/internal/idlewatcher/watcher.go index fa8bc2b2..5d5e7fd5 100644 --- a/internal/idlewatcher/watcher.go +++ b/internal/idlewatcher/watcher.go @@ -20,7 +20,7 @@ import ( idlewatcher "github.com/yusing/godoxy/internal/idlewatcher/types" nettypes "github.com/yusing/godoxy/internal/net/types" "github.com/yusing/godoxy/internal/types" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" gperr "github.com/yusing/goutils/errs" gevents "github.com/yusing/goutils/events" "github.com/yusing/goutils/http/reverseproxy" @@ -577,9 +577,9 @@ func (w *Watcher) watchUntilDestroy() (returnCause error) { case e := <-eventCh: w.l.Debug().Stringer("action", e.Action).Msg("state changed") switch e.Action { - case events.ActionContainerDestroy: + case watcherEvents.ActionContainerDestroy: return errCauseContainerDestroy - case events.ActionForceReload: + case watcherEvents.ActionForceReload: continue } w.resetIdleTimer() diff --git a/internal/net/gphttp/middleware/errorpage/error_page.go b/internal/net/gphttp/middleware/errorpage/error_page.go index 3eaede87..dc4f2431 100644 --- a/internal/net/gphttp/middleware/errorpage/error_page.go +++ b/internal/net/gphttp/middleware/errorpage/error_page.go @@ -10,7 +10,7 @@ import ( "github.com/rs/zerolog/log" "github.com/yusing/godoxy/internal/common" "github.com/yusing/godoxy/internal/watcher" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" "github.com/yusing/goutils/fs" "github.com/yusing/goutils/task" ) @@ -80,13 +80,13 @@ func watchDir() { } filename := event.ActorName switch event.Action { - case events.ActionFileWritten: + case watcherEvents.ActionFileWritten: fileContentMap.Delete(filename) loadContent() - case events.ActionFileDeleted: + case watcherEvents.ActionFileDeleted: fileContentMap.Delete(filename) log.Warn().Msgf("error page resource %s deleted", filename) - case events.ActionFileRenamed: + case watcherEvents.ActionFileRenamed: log.Warn().Msgf("error page resource %s deleted", filename) fileContentMap.Delete(filename) loadContent() diff --git a/internal/route/provider/provider.go b/internal/route/provider/provider.go index 2389c672..e9c01866 100644 --- a/internal/route/provider/provider.go +++ b/internal/route/provider/provider.go @@ -15,7 +15,7 @@ import ( provider "github.com/yusing/godoxy/internal/route/provider/types" "github.com/yusing/godoxy/internal/types" W "github.com/yusing/godoxy/internal/watcher" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" gperr "github.com/yusing/goutils/errs" "github.com/yusing/goutils/eventqueue" "github.com/yusing/goutils/task" @@ -116,9 +116,9 @@ func (p *Provider) Start(parent task.Parent) error { err := errs.Wait().Error() - opts := eventqueue.Options[events.Event]{ + opts := eventqueue.Options[watcherEvents.Event]{ FlushInterval: providerEventFlushInterval, - OnFlush: func(events []events.Event) { + OnFlush: func(events []watcherEvents.Event) { handler := p.newEventHandler() // routes' lifetime should follow the provider's lifetime handler.Handle(t, events) diff --git a/internal/watcher/directory_watcher.go b/internal/watcher/directory_watcher.go index bc061734..f8e71e0c 100644 --- a/internal/watcher/directory_watcher.go +++ b/internal/watcher/directory_watcher.go @@ -9,7 +9,7 @@ import ( "github.com/fsnotify/fsnotify" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" "github.com/yusing/goutils/task" ) @@ -117,18 +117,18 @@ func (h *DirWatcher) start() { } msg := Event{ - Type: events.EventTypeFile, + Type: watcherEvents.EventTypeFile, ActorName: relPath, } switch { case fsEvent.Has(fsnotify.Write): - msg.Action = events.ActionFileWritten + msg.Action = watcherEvents.ActionFileWritten case fsEvent.Has(fsnotify.Create): - msg.Action = events.ActionFileCreated + msg.Action = watcherEvents.ActionFileCreated case fsEvent.Has(fsnotify.Remove): - msg.Action = events.ActionFileDeleted + msg.Action = watcherEvents.ActionFileDeleted case fsEvent.Has(fsnotify.Rename): - msg.Action = events.ActionFileRenamed + msg.Action = watcherEvents.ActionFileRenamed default: // ignore other events continue } diff --git a/internal/watcher/docker_watcher.go b/internal/watcher/docker_watcher.go index f8a4c49b..832a8e0b 100644 --- a/internal/watcher/docker_watcher.go +++ b/internal/watcher/docker_watcher.go @@ -11,7 +11,7 @@ import ( "github.com/rs/zerolog/log" "github.com/yusing/godoxy/internal/docker" "github.com/yusing/godoxy/internal/types" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" ) type ( @@ -64,8 +64,8 @@ var ( dockerWatcherRetryInterval = 3 * time.Second reloadTrigger = Event{ - Type: events.EventTypeDocker, - Action: events.ActionForceReload, + Type: watcherEvents.EventTypeDocker, + Action: watcherEvents.ActionForceReload, ActorAttributes: map[string]string{}, ActorName: "", ActorID: "", @@ -157,12 +157,12 @@ func (w DockerWatcher) parseError(err error) error { } func (w DockerWatcher) handleEvent(event dockerEvents.Message, ch chan<- Event) { - action, ok := events.DockerEventMap[event.Action] + action, ok := watcherEvents.DockerEventMap[event.Action] if !ok { return } ch <- Event{ - Type: events.EventTypeDocker, + Type: watcherEvents.EventTypeDocker, ActorID: event.Actor.ID, ActorAttributes: event.Actor.Attributes, // labels ActorName: event.Actor.Attributes["name"], diff --git a/internal/watcher/events/events.go b/internal/watcher/events/events.go index 994a8aee..70249dbd 100644 --- a/internal/watcher/events/events.go +++ b/internal/watcher/events/events.go @@ -1,4 +1,4 @@ -package events +package watcherevents import ( "fmt" diff --git a/internal/watcher/watcher.go b/internal/watcher/watcher.go index 7068e8ed..245ad58a 100644 --- a/internal/watcher/watcher.go +++ b/internal/watcher/watcher.go @@ -3,10 +3,10 @@ package watcher import ( "context" - "github.com/yusing/godoxy/internal/watcher/events" + watcherEvents "github.com/yusing/godoxy/internal/watcher/events" ) -type Event = events.Event +type Event = watcherEvents.Event type Watcher interface { Events(ctx context.Context) (<-chan Event, <-chan error)