client: move discovery path logic into client pkg

This commit is contained in:
Brian Waldon 2014-10-24 10:45:49 -07:00
parent ce4df96e69
commit 45d8fbdcda
2 changed files with 11 additions and 13 deletions

View File

@ -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) {

View File

@ -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,