|
|
@@ -55,8 +55,6 @@ func newHTTPKeysAPIWithPrefix(tr *http.Transport, ep string, to time.Duration, p
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- u.Path = path.Join(u.Path, prefix)
|
|
|
-
|
|
|
c := &httpClient{
|
|
|
transport: tr,
|
|
|
endpoint: *u,
|
|
|
@@ -65,6 +63,7 @@ func newHTTPKeysAPIWithPrefix(tr *http.Transport, ep string, to time.Duration, p
|
|
|
|
|
|
kAPI := httpKeysAPI{
|
|
|
client: c,
|
|
|
+ prefix: prefix,
|
|
|
}
|
|
|
|
|
|
return &kAPI, nil
|
|
|
@@ -102,12 +101,14 @@ func (n *Node) String() string {
|
|
|
|
|
|
type httpKeysAPI struct {
|
|
|
client *httpClient
|
|
|
+ prefix string
|
|
|
}
|
|
|
|
|
|
func (k *httpKeysAPI) Create(key, val string, ttl time.Duration) (*Response, error) {
|
|
|
create := &createAction{
|
|
|
- Key: key,
|
|
|
- Value: val,
|
|
|
+ Prefix: k.prefix,
|
|
|
+ Key: key,
|
|
|
+ Value: val,
|
|
|
}
|
|
|
if ttl >= 0 {
|
|
|
uttl := uint64(ttl.Seconds())
|
|
|
@@ -124,6 +125,7 @@ func (k *httpKeysAPI) Create(key, val string, ttl time.Duration) (*Response, err
|
|
|
|
|
|
func (k *httpKeysAPI) Get(key string) (*Response, error) {
|
|
|
get := &getAction{
|
|
|
+ Prefix: k.prefix,
|
|
|
Key: key,
|
|
|
Recursive: false,
|
|
|
}
|
|
|
@@ -140,6 +142,7 @@ func (k *httpKeysAPI) Watch(key string, idx uint64) Watcher {
|
|
|
return &httpWatcher{
|
|
|
client: k.client,
|
|
|
nextWait: waitAction{
|
|
|
+ Prefix: k.prefix,
|
|
|
Key: key,
|
|
|
WaitIndex: idx,
|
|
|
Recursive: false,
|
|
|
@@ -151,6 +154,7 @@ func (k *httpKeysAPI) RecursiveWatch(key string, idx uint64) Watcher {
|
|
|
return &httpWatcher{
|
|
|
client: k.client,
|
|
|
nextWait: waitAction{
|
|
|
+ Prefix: k.prefix,
|
|
|
Key: key,
|
|
|
WaitIndex: idx,
|
|
|
Recursive: true,
|
|
|
@@ -179,21 +183,24 @@ func (hw *httpWatcher) Next() (*Response, error) {
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
-// v2KeysURL forms a URL representing the location of a key. The provided
|
|
|
-// endpoint must be the root of the etcd keys API. For example, a valid
|
|
|
-// endpoint probably has the path "/v2/keys".
|
|
|
-func v2KeysURL(ep url.URL, key string) *url.URL {
|
|
|
- ep.Path = path.Join(ep.Path, key)
|
|
|
+// v2KeysURL forms a URL representing the location of a key.
|
|
|
+// The endpoint argument represents the base URL of an etcd
|
|
|
+// server. The prefix is the path needed to route from the
|
|
|
+// provided endpoint's path to the root of the keys API
|
|
|
+// (typically "/v2/keys").
|
|
|
+func v2KeysURL(ep url.URL, prefix, key string) *url.URL {
|
|
|
+ ep.Path = path.Join(ep.Path, prefix, key)
|
|
|
return &ep
|
|
|
}
|
|
|
|
|
|
type getAction struct {
|
|
|
+ Prefix string
|
|
|
Key string
|
|
|
Recursive bool
|
|
|
}
|
|
|
|
|
|
func (g *getAction) httpRequest(ep url.URL) *http.Request {
|
|
|
- u := v2KeysURL(ep, g.Key)
|
|
|
+ u := v2KeysURL(ep, g.Prefix, g.Key)
|
|
|
|
|
|
params := u.Query()
|
|
|
params.Set("recursive", strconv.FormatBool(g.Recursive))
|
|
|
@@ -204,13 +211,14 @@ func (g *getAction) httpRequest(ep url.URL) *http.Request {
|
|
|
}
|
|
|
|
|
|
type waitAction struct {
|
|
|
+ Prefix string
|
|
|
Key string
|
|
|
WaitIndex uint64
|
|
|
Recursive bool
|
|
|
}
|
|
|
|
|
|
func (w *waitAction) httpRequest(ep url.URL) *http.Request {
|
|
|
- u := v2KeysURL(ep, w.Key)
|
|
|
+ u := v2KeysURL(ep, w.Prefix, w.Key)
|
|
|
|
|
|
params := u.Query()
|
|
|
params.Set("wait", "true")
|
|
|
@@ -223,13 +231,14 @@ func (w *waitAction) httpRequest(ep url.URL) *http.Request {
|
|
|
}
|
|
|
|
|
|
type createAction struct {
|
|
|
- Key string
|
|
|
- Value string
|
|
|
- TTL *uint64
|
|
|
+ Prefix string
|
|
|
+ Key string
|
|
|
+ Value string
|
|
|
+ TTL *uint64
|
|
|
}
|
|
|
|
|
|
func (c *createAction) httpRequest(ep url.URL) *http.Request {
|
|
|
- u := v2KeysURL(ep, c.Key)
|
|
|
+ u := v2KeysURL(ep, c.Prefix, c.Key)
|
|
|
|
|
|
params := u.Query()
|
|
|
params.Set("prevExist", "false")
|