Browse Source

client: move discovery path logic into client pkg

Brian Waldon 11 years ago
parent
commit
45d8fbdcda
2 changed files with 11 additions and 13 deletions
  1. 10 9
      client/keys.go
  2. 1 4
      discovery/discovery.go

+ 10 - 9
client/keys.go

@@ -41,7 +41,15 @@ var (
 	ErrKeyExists   = errors.New("client: key already exists")
 )
 
-func NewKeysAPI(tr *http.Transport, ep string, to time.Duration) (*HTTPKeysAPI, error) {
+func NewKeysAPI(tr *http.Transport, ep string, to time.Duration) (KeysAPI, error) {
+	return newHTTPKeysAPIWithPrefix(tr, ep, to, DefaultV2KeysPrefix)
+}
+
+func NewDiscoveryKeysAPI(tr *http.Transport, ep string, to time.Duration) (KeysAPI, error) {
+	return newHTTPKeysAPIWithPrefix(tr, ep, to, "")
+}
+
+func newHTTPKeysAPIWithPrefix(tr *http.Transport, ep string, to time.Duration, prefix string) (*HTTPKeysAPI, error) {
 	c, err := newHTTPClient(tr, ep, to)
 	if err != nil {
 		return nil, err
@@ -85,14 +93,7 @@ func (n *Node) String() string {
 }
 
 type HTTPKeysAPI struct {
-	client   *httpClient
-	endpoint url.URL
-}
-
-func (k *HTTPKeysAPI) SetAPIPrefix(p string) {
-	ep := k.endpoint
-	ep.Path = path.Join(ep.Path, p)
-	k.client.endpoint = ep
+	client *httpClient
 }
 
 func (k *HTTPKeysAPI) Create(key, val string, ttl time.Duration) (*Response, error) {

+ 1 - 4
discovery/discovery.go

@@ -105,13 +105,10 @@ func New(durl string, id uint64, config string) (Discoverer, error) {
 	if err != nil {
 		return nil, err
 	}
-	c, err := client.NewKeysAPI(&http.Transport{Proxy: pf}, u.String(), time.Second*5)
+	c, err := client.NewDiscoveryKeysAPI(&http.Transport{Proxy: pf}, u.String(), time.Second*5)
 	if err != nil {
 		return nil, err
 	}
-	// discovery service redirects /[key] to /v2/keys/[key]
-	// set the prefix of client to "" to handle this
-	c.SetAPIPrefix("")
 	return &discovery{
 		cluster: token,
 		id:      id,