event.go 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package store
  2. const (
  3. Get = "get"
  4. Create = "create"
  5. Set = "set"
  6. Update = "update"
  7. Delete = "delete"
  8. CompareAndSwap = "compareAndSwap"
  9. CompareAndDelete = "compareAndDelete"
  10. Expire = "expire"
  11. )
  12. type Event struct {
  13. Action string `json:"action"`
  14. Node *NodeExtern `json:"node,omitempty"`
  15. PrevNode *NodeExtern `json:"prevNode,omitempty"`
  16. }
  17. func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
  18. n := &NodeExtern{
  19. Key: key,
  20. ModifiedIndex: modifiedIndex,
  21. CreatedIndex: createdIndex,
  22. }
  23. return &Event{
  24. Action: action,
  25. Node: n,
  26. }
  27. }
  28. func (e *Event) IsCreated() bool {
  29. if e.Action == Create {
  30. return true
  31. }
  32. if e.Action == Set && e.PrevNode == nil {
  33. return true
  34. }
  35. return false
  36. }
  37. func (e *Event) Index() uint64 {
  38. return e.Node.ModifiedIndex
  39. }