mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 16:01:22 +02:00
refactor: minor styling fixes; deadcode cleanup and correct log level
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user