| 1 |
package watchers |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"runtime" |
| 6 |
) |
| 7 |
|
| 8 |
// FSWatcher is a file system watcher |
| 9 |
type FSWatcher interface { |
| 10 |
Configure(string) error |
| 11 |
Events() chan *FSEvent |
| 12 |
// Adds a directory or file to the watcher |
| 13 |
Add(string) error |
| 14 |
// Removes a directory or file from the watcher |
| 15 |
Remove(string) error |
| 16 |
} |
| 17 |
|
| 18 |
type FSOperation int |
| 19 |
|
| 20 |
const ( |
| 21 |
FSCreate FSOperation = iota |
| 22 |
FSRemove |
| 23 |
FSRename |
| 24 |
) |
| 25 |
|
| 26 |
type FSEvent struct { |
| 27 |
Operation FSOperation |
| 28 |
Path string |
| 29 |
} |
| 30 |
|
| 31 |
type WatcherFactoryFunc func() (FSWatcher, error) |
| 32 |
|
| 33 |
var watcherFactory WatcherFactoryFunc |
| 34 |
|
| 35 |
func RegisterWatcherFactory(fn WatcherFactoryFunc) { |
| 36 |
watcherFactory = fn |
| 37 |
} |
| 38 |
|
| 39 |
func NewWatcher() (FSWatcher, error) { |
| 40 |
if watcherFactory == nil { |
| 41 |
return nil, fmt.Errorf("Unsupported OS: %s", runtime.GOOS) |
| 42 |
} |
| 43 |
return watcherFactory() |
| 44 |
} |