mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client: pass httpActionDo into New[Discovery]KeysAPI
This commit is contained in:
parent
1130273178
commit
0ef270c25c
@ -41,27 +41,20 @@ var (
|
|||||||
ErrKeyExists = errors.New("client: key already exists")
|
ErrKeyExists = errors.New("client: key already exists")
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewKeysAPI(tr *http.Transport, eps []string, to time.Duration) (KeysAPI, error) {
|
func NewKeysAPI(c httpActionDo, to time.Duration) KeysAPI {
|
||||||
return newHTTPKeysAPIWithPrefix(tr, eps, to, DefaultV2KeysPrefix)
|
return &httpKeysAPI{
|
||||||
}
|
|
||||||
|
|
||||||
func NewDiscoveryKeysAPI(tr *http.Transport, eps []string, to time.Duration) (KeysAPI, error) {
|
|
||||||
return newHTTPKeysAPIWithPrefix(tr, eps, to, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func newHTTPKeysAPIWithPrefix(tr *http.Transport, eps []string, to time.Duration, prefix string) (*httpKeysAPI, error) {
|
|
||||||
c, err := NewHTTPClient(tr, eps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
kAPI := httpKeysAPI{
|
|
||||||
client: c,
|
client: c,
|
||||||
prefix: prefix,
|
prefix: DefaultV2KeysPrefix,
|
||||||
timeout: to,
|
timeout: to,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &kAPI, nil
|
func NewDiscoveryKeysAPI(c httpActionDo, to time.Duration) KeysAPI {
|
||||||
|
return &httpKeysAPI{
|
||||||
|
client: c,
|
||||||
|
prefix: "",
|
||||||
|
timeout: to,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeysAPI interface {
|
type KeysAPI interface {
|
||||||
|
@ -106,15 +106,16 @@ func New(durl string, id types.ID, config string) (Discoverer, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c, err := client.NewDiscoveryKeysAPI(&http.Transport{Proxy: pf}, []string{u.String()}, client.DefaultRequestTimeout)
|
c, err := client.NewHTTPClient(&http.Transport{Proxy: pf}, []string{u.String()})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
dc := client.NewDiscoveryKeysAPI(c, client.DefaultRequestTimeout)
|
||||||
return &discovery{
|
return &discovery{
|
||||||
cluster: token,
|
cluster: token,
|
||||||
id: id,
|
id: id,
|
||||||
config: config,
|
config: config,
|
||||||
c: c,
|
c: dc,
|
||||||
url: u,
|
url: u,
|
||||||
clock: clockwork.NewRealClock(),
|
clock: clockwork.NewRealClock(),
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user