client: add Nodes type to faciliate sorting

This helps users to sort easily.
release-2.3
Yicheng Qin 2015-09-10 11:03:12 -07:00
parent db0511e28c
commit eb51901830
1 changed files with 8 additions and 1 deletions

View File

@ -279,7 +279,7 @@ type Node struct {
// Nodes holds the children of this Node, only if this Node is a directory.
// This slice of will be arbitrarily deep (children, grandchildren, great-
// grandchildren, etc.) if a recursive Get or Watch request were made.
Nodes []*Node `json:"nodes"`
Nodes Nodes `json:"nodes"`
// CreatedIndex is the etcd index at-which this Node was created.
CreatedIndex uint64 `json:"createdIndex"`
@ -303,6 +303,13 @@ func (n *Node) TTLDuration() time.Duration {
return time.Duration(n.TTL) * time.Second
}
type Nodes []*Node
// interfaces for sorting
func (ns Nodes) Len() int { return len(ns) }
func (ns Nodes) Less(i, j int) bool { return ns[i].Key < ns[j].Key }
func (ns Nodes) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
type httpKeysAPI struct {
client httpClient
prefix string