소스 검색

client: pass httpActionDo into New[Discovery]KeysAPI

Brian Waldon 11 년 전
부모
커밋
0ef270c25c
2개의 변경된 파일12개의 추가작업 그리고 18개의 파일을 삭제
  1. 9 16
      client/keys.go
  2. 3 2
      discovery/discovery.go

+ 9 - 16
client/keys.go

@@ -41,27 +41,20 @@ var (
 	ErrKeyExists   = errors.New("client: key already exists")
 )
 
-func NewKeysAPI(tr *http.Transport, eps []string, to time.Duration) (KeysAPI, error) {
-	return newHTTPKeysAPIWithPrefix(tr, eps, to, DefaultV2KeysPrefix)
-}
-
-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
+func NewKeysAPI(c httpActionDo, to time.Duration) KeysAPI {
+	return &httpKeysAPI{
+		client:  c,
+		prefix:  DefaultV2KeysPrefix,
+		timeout: to,
 	}
+}
 
-	kAPI := httpKeysAPI{
+func NewDiscoveryKeysAPI(c httpActionDo, to time.Duration) KeysAPI {
+	return &httpKeysAPI{
 		client:  c,
-		prefix:  prefix,
+		prefix:  "",
 		timeout: to,
 	}
-
-	return &kAPI, nil
 }
 
 type KeysAPI interface {

+ 3 - 2
discovery/discovery.go

@@ -106,15 +106,16 @@ func New(durl string, id types.ID, config string) (Discoverer, error) {
 	if err != nil {
 		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 {
 		return nil, err
 	}
+	dc := client.NewDiscoveryKeysAPI(c, client.DefaultRequestTimeout)
 	return &discovery{
 		cluster: token,
 		id:      id,
 		config:  config,
-		c:       c,
+		c:       dc,
 		url:     u,
 		clock:   clockwork.NewRealClock(),
 	}, nil