-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcloudwatcher.go
52 lines (41 loc) · 1.08 KB
/
cloudwatcher.go
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
45
46
47
48
49
50
51
52
package cloudwatcher
import (
"fmt"
"time"
)
type storageFunc func(dir string, interval time.Duration) (Watcher, error)
var supportedServices map[string]storageFunc
// WatcherBase is the struct included in all the specialized watchers
type WatcherBase struct {
Events chan Event
Errors chan error
watchDir string
pollingTime time.Duration
}
// Watcher has to be implemented by all the watchers
type Watcher interface {
Start() error
SetConfig(c map[string]string) error
Close()
GetEvents() chan Event
GetErrors() chan error
}
// New creates a new instance of a watcher
func New(serviceName string, dir string, interval time.Duration) (Watcher, error) {
f, ok := supportedServices[serviceName]
if !ok {
return nil, fmt.Errorf("service %s is not yet supported", serviceName)
}
return f(dir, interval)
}
// GetEvents returns a chan of Event
func (w *WatcherBase) GetEvents() chan Event {
return w.Events
}
// GetErrors returns a chan of error
func (w *WatcherBase) GetErrors() chan error {
return w.Errors
}
func init() {
supportedServices = make(map[string]storageFunc)
}