forked from philchia/agollo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change.go
61 lines (52 loc) · 941 Bytes
/
change.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
package agollo
// ChangeType for a key
type ChangeType int
const (
// ADD a new value
ADD ChangeType = iota
// MODIFY a old value
MODIFY
// DELETE ...
DELETE
)
func (c ChangeType) String() string {
switch c {
case ADD:
return "ADD"
case MODIFY:
return "MODIFY"
case DELETE:
return "DELETE"
}
return "UNKNOW"
}
// ChangeEvent change event
type ChangeEvent struct {
Namespace string
Changes map[string]*Change
}
// Change represent a single key change
type Change struct {
OldValue string
NewValue string
ChangeType ChangeType
}
func makeDeleteChange(_, value string) *Change {
return &Change{
ChangeType: DELETE,
OldValue: value,
}
}
func makeModifyChange(_, oldValue, newValue string) *Change {
return &Change{
ChangeType: MODIFY,
OldValue: oldValue,
NewValue: newValue,
}
}
func makeAddChange(_, value string) *Change {
return &Change{
ChangeType: ADD,
NewValue: value,
}
}