mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
48 lines
894 B
Go
48 lines
894 B
Go
package store
|
|
|
|
const (
|
|
Get = "get"
|
|
Create = "create"
|
|
Set = "set"
|
|
Update = "update"
|
|
Delete = "delete"
|
|
CompareAndSwap = "compareAndSwap"
|
|
CompareAndDelete = "compareAndDelete"
|
|
Expire = "expire"
|
|
)
|
|
|
|
type Event struct {
|
|
Action string `json:"action"`
|
|
Node *NodeExtern `json:"node,omitempty"`
|
|
PrevNode *NodeExtern `json:"prevNode,omitempty"`
|
|
}
|
|
|
|
func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
|
|
n := &NodeExtern{
|
|
Key: key,
|
|
ModifiedIndex: modifiedIndex,
|
|
CreatedIndex: createdIndex,
|
|
}
|
|
|
|
return &Event{
|
|
Action: action,
|
|
Node: n,
|
|
}
|
|
}
|
|
|
|
func (e *Event) IsCreated() bool {
|
|
if e.Action == Create {
|
|
return true
|
|
}
|
|
|
|
if e.Action == Set && e.PrevNode == nil {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (e *Event) Index() uint64 {
|
|
return e.Node.ModifiedIndex
|
|
}
|