aboutsummaryrefslogtreecommitdiff
path: root/lib/watchers/watchers.go
blob: 06ef985c6b994e5ed89d8861fe5db0d444e68da7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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()
}