...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package v2store
16
17 const (
18 Get = "get"
19 Create = "create"
20 Set = "set"
21 Update = "update"
22 Delete = "delete"
23 CompareAndSwap = "compareAndSwap"
24 CompareAndDelete = "compareAndDelete"
25 Expire = "expire"
26 )
27
28 type Event struct {
29 Action string `json:"action"`
30 Node *NodeExtern `json:"node,omitempty"`
31 PrevNode *NodeExtern `json:"prevNode,omitempty"`
32 EtcdIndex uint64 `json:"-"`
33 Refresh bool `json:"refresh,omitempty"`
34 }
35
36 func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
37 n := &NodeExtern{
38 Key: key,
39 ModifiedIndex: modifiedIndex,
40 CreatedIndex: createdIndex,
41 }
42
43 return &Event{
44 Action: action,
45 Node: n,
46 }
47 }
48
49 func (e *Event) IsCreated() bool {
50 if e.Action == Create {
51 return true
52 }
53 return e.Action == Set && e.PrevNode == nil
54 }
55
56 func (e *Event) Index() uint64 {
57 return e.Node.ModifiedIndex
58 }
59
60 func (e *Event) Clone() *Event {
61 return &Event{
62 Action: e.Action,
63 EtcdIndex: e.EtcdIndex,
64 Node: e.Node.Clone(),
65 PrevNode: e.PrevNode.Clone(),
66 }
67 }
68
69 func (e *Event) SetRefresh() {
70 e.Refresh = true
71 }
72
View as plain text