kv_pairs.go 784 B

12345678910111213141516171819202122232425262728293031
  1. package store
  2. import (
  3. "time"
  4. )
  5. // When user list a directory, we add all the node into key-value pair slice
  6. type KeyValuePair struct {
  7. Key string `json:"key, omitempty"`
  8. Value string `json:"value,omitempty"`
  9. Dir bool `json:"dir,omitempty"`
  10. Expiration *time.Time `json:"expiration,omitempty"`
  11. TTL int64 `json:"ttl,omitempty"` // Time to live in second
  12. KVPairs kvPairs `json:"kvs,omitempty"`
  13. ModifiedIndex uint64 `json:"modifiedIndex,omitempty"`
  14. }
  15. type kvPairs []KeyValuePair
  16. // interfaces for sorting
  17. func (kvs kvPairs) Len() int {
  18. return len(kvs)
  19. }
  20. func (kvs kvPairs) Less(i, j int) bool {
  21. return kvs[i].Key < kvs[j].Key
  22. }
  23. func (kvs kvPairs) Swap(i, j int) {
  24. kvs[i], kvs[j] = kvs[j], kvs[i]
  25. }