-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnotice.go
80 lines (66 loc) · 1.4 KB
/
notice.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
74
75
76
77
78
79
80
package fsmonitor
import (
"os"
"strings"
"time"
"fmt"
)
// Event defines different types of changes.
type Event uint32
const (
FileCreate Event = 0x01 << iota
FileUpdate
FileRemove
FileRename
)
// String implements fmt.Stringer.
func (e Event) String() string {
var s []string
for _, strmap := range []map[Event]string{eventName} {
for ev, str := range strmap {
if e&ev == ev {
s = append(s, str)
}
}
}
return strings.Join(s, "|")
}
var eventName = map[Event]string{
FileCreate: "notice.FileCreate",
FileRemove: "notice.FileRemove",
FileUpdate: "notice.FileUpdate",
FileRename: "notice.FileRename",
}
// Notice abstracts basic information needed notification.
// Also include fmt.Stringer to simplify inspecting.
type Notice interface {
// Considered to be uid
Name() string
// Timestamp when created
Time() time.Time
Type() Event
More() interface{}
fmt.Stringer
}
// Implements Notice, uses file name as Notice.Name
type fileSystemNotice struct {
path string
event Event
fileinfo os.FileInfo
timestamp time.Time
}
func (f *fileSystemNotice) String() string{
return fmt.Sprintf("{%v : %v}",f.path, f.event)
}
func (f *fileSystemNotice) Name() string {
return f.path
}
func (f *fileSystemNotice) Type() Event {
return f.event
}
func (f *fileSystemNotice) More() interface{} {
return f.fileinfo
}
func (f *fileSystemNotice) Time() time.Time {
return f.timestamp
}