aboutsummaryrefslogtreecommitdiff
path: root/lib/watchers/watchers.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/watchers/watchers.go')
-rw-r--r--lib/watchers/watchers.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/watchers/watchers.go b/lib/watchers/watchers.go
new file mode 100644
index 00000000..06ef985c
--- /dev/null
+++ b/lib/watchers/watchers.go
@@ -0,0 +1,44 @@
+package watchers
+
+import (
+ "fmt"
+ "runtime"
+)
+
+// FSWatcher is a file system watcher
+type FSWatcher interface {
+ Configure(string) error
+ Events() chan *FSEvent
+ // Adds a directory or file to the watcher
+ Add(string) error
+ // Removes a directory or file from the watcher
+ Remove(string) error
+}
+
+type FSOperation int
+
+const (
+ FSCreate FSOperation = iota
+ FSRemove
+ FSRename
+)
+
+type FSEvent struct {
+ Operation FSOperation
+ Path string
+}
+
+type WatcherFactoryFunc func() (FSWatcher, error)
+
+var watcherFactory WatcherFactoryFunc
+
+func RegisterWatcherFactory(fn WatcherFactoryFunc) {
+ watcherFactory = fn
+}
+
+func NewWatcher() (FSWatcher, error) {
+ if watcherFactory == nil {
+ return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS)
+ }
+ return watcherFactory()
+}