-
Notifications
You must be signed in to change notification settings - Fork 43
/
handler.go
73 lines (64 loc) · 1.8 KB
/
handler.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package watcher
import (
"context"
"fmt"
"os"
"github.com/FleekHQ/space-daemon/log"
)
// EventHandler
type EventHandler interface {
OnCreate(ctx context.Context, path string, fileInfo os.FileInfo)
OnRemove(ctx context.Context, path string, fileInfo os.FileInfo)
OnWrite(ctx context.Context, path string, fileInfo os.FileInfo)
OnRename(ctx context.Context, path string, fileInfo os.FileInfo, oldPath string)
OnMove(ctx context.Context, path string, fileInfo os.FileInfo, oldPath string)
}
// Implements EventHandler and defaults to logging actions performed
type defaultWatcherHandler struct{}
func (h *defaultWatcherHandler) OnCreate(
ctx context.Context,
path string,
fileInfo os.FileInfo,
) {
log.Info("Default Watcher Handler: OnCreate", fmt.Sprintf("path:%s", path), fmt.Sprintf("fileInfo:%v", fileInfo))
}
func (h *defaultWatcherHandler) OnRemove(
ctx context.Context,
path string,
fileInfo os.FileInfo,
) {
log.Info("Default Watcher Handler: OnRemove", fmt.Sprintf("path:%s", path), fmt.Sprintf("fileInfo:%v", fileInfo))
}
func (h *defaultWatcherHandler) OnWrite(
ctx context.Context,
path string,
fileInfo os.FileInfo,
) {
log.Info("Default Watcher Handler: OnWrite", fmt.Sprintf("path:%s", path), fmt.Sprintf("fileInfo:%v", fileInfo))
}
func (h *defaultWatcherHandler) OnRename(
ctx context.Context,
path string,
fileInfo os.FileInfo,
oldPath string,
) {
log.Info(
"Default Watcher Handler: OnRename",
fmt.Sprintf("path:%s", path),
fmt.Sprintf("fileInfo:%v", fileInfo),
fmt.Sprintf("path:%s", oldPath),
)
}
func (h *defaultWatcherHandler) OnMove(
ctx context.Context,
path string,
fileInfo os.FileInfo,
oldPath string,
) {
log.Info(
"Default Watcher Handler: OnMove",
fmt.Sprintf("path:%s", path),
fmt.Sprintf("fileInfo:%v", fileInfo),
fmt.Sprintf("path:%s", oldPath),
)
}