refactor: minor styling fixes; deadcode cleanup and correct log level

This commit is contained in:
yusing
2026-02-15 20:01:36 +08:00
parent 35b8a60edb
commit 154149b06d
29 changed files with 88 additions and 67 deletions

View File

@@ -17,7 +17,7 @@ func initConfigDirWatcher() {
configDirWatcher = NewDirectoryWatcher(t, common.ConfigBasePath)
}
// NewConfigFileWatcher creates a new file watcher for file under common.ConfigBasePath.
// NewConfigFileWatcher creates a new file watcher for a file under common.ConfigBasePath.
func NewConfigFileWatcher(filename string) Watcher {
configDirWatcherInitOnce.Do(initConfigDirWatcher)
return configDirWatcher.Add(filename)

View File

@@ -61,6 +61,9 @@ func NewDirectoryWatcher(parent task.Parent, dirPath string) *DirWatcher {
return helper
}
var _ Watcher = (*DirWatcher)(nil)
// Events implements the Watcher interface.
func (h *DirWatcher) Events(_ context.Context) (<-chan Event, <-chan error) {
return h.eventCh, h.errCh
}
@@ -112,7 +115,7 @@ func (h *DirWatcher) start() {
relPath := strings.TrimPrefix(fsEvent.Name, h.dir)
relPath = strings.TrimPrefix(relPath, "/")
if len(relPath) > 0 && relPath[0] == '.' { // hideden file
if len(relPath) > 0 && relPath[0] == '.' { // hidden file
continue
}

View File

@@ -82,6 +82,9 @@ func NewDockerWatcher(dockerCfg types.DockerProviderConfig) DockerWatcher {
}
}
var _ Watcher = (*DockerWatcher)(nil)
// Events implements the Watcher interface.
func (w DockerWatcher) Events(ctx context.Context) (<-chan Event, <-chan error) {
return w.EventsWithOptions(ctx, optionsDefault)
}
@@ -123,11 +126,11 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
eventCh <- reloadTrigger
retry := time.NewTicker(dockerWatcherRetryInterval)
defer retry.Stop()
outer:
for {
select {
case <-ctx.Done():
retry.Stop()
return
case <-retry.C:
if checkConnection(ctx, client) {
@@ -135,6 +138,7 @@ func (w DockerWatcher) EventsWithOptions(ctx context.Context, options DockerList
}
}
}
retry.Stop()
// connection successful, trigger reload (reload routes)
eventCh <- reloadTrigger
// reopen event channel

View File

@@ -10,6 +10,9 @@ type fileWatcher struct {
errCh chan error
}
var _ Watcher = (*fileWatcher)(nil)
// Events implements the Watcher interface.
func (fw *fileWatcher) Events(ctx context.Context) (<-chan Event, <-chan error) {
return fw.eventCh, fw.errCh
}