mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: add GetOptions.Sort
This commit is contained in:
parent
84ede6fbec
commit
479a17dcbf
@ -115,6 +115,13 @@ type GetOptions struct {
|
||||
// Recursive defines whether or not all children of the Node
|
||||
// should be returned.
|
||||
Recursive bool
|
||||
|
||||
// Sort instructs the server whether or not to sort the Nodes.
|
||||
// If true, the Nodes are sorted alphabetically by key in
|
||||
// ascending order (A to z). If false (default), the Nodes will
|
||||
// not be sorted and the ordering used should not be considered
|
||||
// predictable.
|
||||
Sort bool
|
||||
}
|
||||
|
||||
type DeleteOptions struct {
|
||||
@ -236,6 +243,7 @@ func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*R
|
||||
|
||||
if opts != nil {
|
||||
act.Recursive = opts.Recursive
|
||||
act.Sorted = opts.Sort
|
||||
}
|
||||
|
||||
resp, body, err := k.client.Do(ctx, act)
|
||||
@ -297,6 +305,7 @@ type getAction struct {
|
||||
Prefix string
|
||||
Key string
|
||||
Recursive bool
|
||||
Sorted bool
|
||||
}
|
||||
|
||||
func (g *getAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
@ -304,6 +313,7 @@ func (g *getAction) HTTPRequest(ep url.URL) *http.Request {
|
||||
|
||||
params := u.Query()
|
||||
params.Set("recursive", strconv.FormatBool(g.Recursive))
|
||||
params.Set("sorted", strconv.FormatBool(g.Sorted))
|
||||
u.RawQuery = params.Encode()
|
||||
|
||||
req, _ := http.NewRequest("GET", u.String(), nil)
|
||||
|
@ -99,15 +99,28 @@ func TestGetAction(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
recursive bool
|
||||
sorted bool
|
||||
wantQuery string
|
||||
}{
|
||||
{
|
||||
recursive: false,
|
||||
wantQuery: "recursive=false",
|
||||
sorted: false,
|
||||
wantQuery: "recursive=false&sorted=false",
|
||||
},
|
||||
{
|
||||
recursive: true,
|
||||
wantQuery: "recursive=true",
|
||||
sorted: false,
|
||||
wantQuery: "recursive=true&sorted=false",
|
||||
},
|
||||
{
|
||||
recursive: false,
|
||||
sorted: true,
|
||||
wantQuery: "recursive=false&sorted=true",
|
||||
},
|
||||
{
|
||||
recursive: true,
|
||||
sorted: true,
|
||||
wantQuery: "recursive=true&sorted=true",
|
||||
},
|
||||
}
|
||||
|
||||
@ -115,6 +128,7 @@ func TestGetAction(t *testing.T) {
|
||||
f := getAction{
|
||||
Key: "/foo/bar",
|
||||
Recursive: tt.recursive,
|
||||
Sorted: tt.sorted,
|
||||
}
|
||||
got := *f.HTTPRequest(ep)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user