mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: move discovery path logic into client pkg
This commit is contained in:
parent
ce4df96e69
commit
45d8fbdcda
@ -41,7 +41,15 @@ var (
|
|||||||
ErrKeyExists = errors.New("client: key already exists")
|
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)
|
c, err := newHTTPClient(tr, ep, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -85,14 +93,7 @@ func (n *Node) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type HTTPKeysAPI struct {
|
type HTTPKeysAPI struct {
|
||||||
client *httpClient
|
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *HTTPKeysAPI) Create(key, val string, ttl time.Duration) (*Response, error) {
|
func (k *HTTPKeysAPI) Create(key, val string, ttl time.Duration) (*Response, error) {
|
||||||
|
@ -105,13 +105,10 @@ func New(durl string, id uint64, config string) (Discoverer, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// discovery service redirects /[key] to /v2/keys/[key]
|
|
||||||
// set the prefix of client to "" to handle this
|
|
||||||
c.SetAPIPrefix("")
|
|
||||||
return &discovery{
|
return &discovery{
|
||||||
cluster: token,
|
cluster: token,
|
||||||
id: id,
|
id: id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user