event.go 931 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. EtcdIndex uint64 `json:"-"`
  17. }
  18. func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
  19. n := &NodeExtern{
  20. Key: key,
  21. ModifiedIndex: modifiedIndex,
  22. CreatedIndex: createdIndex,
  23. }
  24. return &Event{
  25. Action: action,
  26. Node: n,
  27. }
  28. }
  29. func (e *Event) IsCreated() bool {
  30. if e.Action == Create {
  31. return true
  32. }
  33. if e.Action == Set && e.PrevNode == nil {
  34. return true
  35. }
  36. return false
  37. }
  38. func (e *Event) Index() uint64 {
  39. return e.Node.ModifiedIndex
  40. }