mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-24 10:01:04 +01:00
refactor(watcher): rename events package to watcherEvents
- Updated import paths and references from events to watcherEvents across multiple files
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"],
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package events
|
||||
package watcherevents
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user