diff --git a/ctrl/internal/core/ports/config_watcher.go b/ctrl/internal/core/ports/configWatcher.go similarity index 100% rename from ctrl/internal/core/ports/config_watcher.go rename to ctrl/internal/core/ports/configWatcher.go diff --git a/ctrl/internal/infrastructure/interaction/yaml_watcher.go b/ctrl/internal/infrastructure/interaction/fileWatcher.go similarity index 84% rename from ctrl/internal/infrastructure/interaction/yaml_watcher.go rename to ctrl/internal/infrastructure/interaction/fileWatcher.go index a198e1ebcacbd210a6b6364379bc63e61fc513f9..b928314b9ab23db00c7b945f7543310cd39fc704 100644 --- a/ctrl/internal/infrastructure/interaction/yaml_watcher.go +++ b/ctrl/internal/infrastructure/interaction/fileWatcher.go @@ -9,8 +9,8 @@ import ( "go.uber.org/zap" ) -// Implement the ConfigWatcher interface for yaml configuration files. -type YamlWatcher struct { +// Implement the ConfigWatcher interface for configuration files. +type FileWatcher struct { // This channel is used to communicate with the outside outgoingChannel chan ports.ChangeNotification directoryPathToWatch string @@ -24,26 +24,27 @@ type YamlWatcher struct { } // NewYamlWatcher creates a new YamlWatcher instance. -func NewYamlWatcher(logger *zap.SugaredLogger) *YamlWatcher { +func NewYamlWatcher(logger *zap.SugaredLogger) *FileWatcher { // Create buffered channel. 1024 is just an arbitrary number. // We expect each notification event to be 32bytes, so 1024 has no meaningful impact to performance. channel := make(chan ports.ChangeNotification, 1024) - return &YamlWatcher{logger: logger, outgoingChannel: channel} + return &FileWatcher{logger: logger, outgoingChannel: channel} } -// ConfigureWatcher configures the watcher with a path and a channel. -func (y *YamlWatcher) ConfigureWatcher(path string) { +// ConfigureWatcher configures the watcher with a path and options. +// Options is here used for the file suffixes the watcher should look for. +func (y *FileWatcher) ConfigureWatcher(path string) { y.directoryPathToWatch = path } // GetChannel returns the channel that is used to communicate with the outside. -func (y *YamlWatcher) GetChannel() chan ports.ChangeNotification { +func (y *FileWatcher) GetChannel() chan ports.ChangeNotification { return y.outgoingChannel } // StartWatcher starts the watcher. -func (y *YamlWatcher) StartWatcher() error { +func (y *FileWatcher) StartWatcher() error { y.logger.Infof("starting watcher for path %s", y.directoryPathToWatch) ctx, cancel := context.WithCancel(context.Background()) @@ -55,7 +56,7 @@ func (y *YamlWatcher) StartWatcher() error { } // StopWatcher stops the watcher. Uses the generic Close() interface. -func (y *YamlWatcher) StopWatcher() error { +func (y *FileWatcher) StopWatcher() error { y.logger.Infof("stopping watcher for path %s", y.directoryPathToWatch) err := y.Close() @@ -67,14 +68,14 @@ func (y *YamlWatcher) StopWatcher() error { } // Close stops the watcher. -func (y *YamlWatcher) Close() error { +func (y *FileWatcher) Close() error { close(y.outgoingChannel) y.watcherCancel() return nil } -func (y *YamlWatcher) watching(ctx context.Context) { +func (y *FileWatcher) watching(ctx context.Context) { watcher, err := fsnotify.NewWatcher() if err != nil { y.logger.Errorw("failed to create watcher", "error", err)