kv_pairs.go 707 B

123456789101112131415161718192021222324252627282930
  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. }
  14. type kvPairs []KeyValuePair
  15. // interfaces for sorting
  16. func (kvs kvPairs) Len() int {
  17. return len(kvs)
  18. }
  19. func (kvs kvPairs) Less(i, j int) bool {
  20. return kvs[i].Key < kvs[j].Key
  21. }
  22. func (kvs kvPairs) Swap(i, j int) {
  23. kvs[i], kvs[j] = kvs[j], kvs[i]
  24. }