go.etcd.io/etcd@v3.3.27+incompatible/store/event.go (about) 1 // Copyright 2015 The etcd Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package store 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 }