client: use options struct for KeysAPI.Get

This commit is contained in:
Brian Waldon
2015-01-28 12:34:06 -08:00
committed by Yicheng Qin
parent 8621caf3e2
commit 84ede6fbec
3 changed files with 22 additions and 30 deletions

View File

@@ -56,14 +56,12 @@ func NewKeysAPIWithPrefix(c Client, p string) KeysAPI {
}
type KeysAPI interface {
Get(ctx context.Context, key string, opts *GetOptions) (*Response, error)
Set(ctx context.Context, key, value string, opts *SetOptions) (*Response, error)
Create(ctx context.Context, key, value string) (*Response, error)
Update(ctx context.Context, key, value string) (*Response, error)
Delete(ctx context.Context, key string, opts *DeleteOptions) (*Response, error)
Get(ctx context.Context, key string) (*Response, error)
RGet(ctx context.Context, key string) (*Response, error)
Create(ctx context.Context, key, value string) (*Response, error)
Update(ctx context.Context, key, value string) (*Response, error)
Watcher(key string, opts *WatcherOptions) Watcher
}
@@ -113,6 +111,12 @@ type SetOptions struct {
TTL time.Duration
}
type GetOptions struct {
// Recursive defines whether or not all children of the Node
// should be returned.
Recursive bool
}
type DeleteOptions struct {
// PrevValue specifies what the current value of the Node must
// be in order for the Delete operation to succeed.
@@ -224,29 +228,17 @@ func (k *httpKeysAPI) Delete(ctx context.Context, key string, opts *DeleteOption
return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body)
}
func (k *httpKeysAPI) Get(ctx context.Context, key string) (*Response, error) {
get := &getAction{
Prefix: k.prefix,
Key: key,
Recursive: false,
func (k *httpKeysAPI) Get(ctx context.Context, key string, opts *GetOptions) (*Response, error) {
act := &getAction{
Prefix: k.prefix,
Key: key,
}
resp, body, err := k.client.Do(ctx, get)
if err != nil {
return nil, err
if opts != nil {
act.Recursive = opts.Recursive
}
return unmarshalHTTPResponse(resp.StatusCode, resp.Header, body)
}
func (k *httpKeysAPI) RGet(ctx context.Context, key string) (*Response, error) {
get := &getAction{
Prefix: k.prefix,
Key: key,
Recursive: true,
}
resp, body, err := k.client.Do(ctx, get)
resp, body, err := k.client.Do(ctx, act)
if err != nil {
return nil, err
}