diff --git a/api/weaveapi.go b/api/weaveapi.go index b49a2969..210618a8 100644 --- a/api/weaveapi.go +++ b/api/weaveapi.go @@ -8,8 +8,6 @@ import ( "net/http" "net/url" "strings" - - . "github.com/weaveworks/weave/common" ) const ( @@ -19,11 +17,12 @@ const ( type Client struct { baseURL string + log Logger } func (client *Client) httpVerb(verb string, url string, values url.Values) (string, error) { url = client.baseURL + url - Log.Debugf("weave %s to %s with %v", verb, url, values) + client.log.Debugf("weave %s to %s with %v", verb, url, values) var body io.Reader if values != nil { body = strings.NewReader(values.Encode()) @@ -50,7 +49,7 @@ func (client *Client) httpVerb(verb string, url string, values url.Values) (stri return "", errors.New(resp.Status + ": " + string(rbody)) } -func NewClient(addr string) *Client { +func NewClient(addr string, log Logger) *Client { host := WeaveHTTPHost port := fmt.Sprintf("%d", WeaveHTTPPort) switch parts := strings.Split(addr, ":"); len(parts) { @@ -67,12 +66,17 @@ func NewClient(addr string) *Client { port = parts[1] } default: - return &Client{baseURL: fmt.Sprintf("http://%s", addr)} + return &Client{baseURL: fmt.Sprintf("http://%s", addr), log: log} } - return &Client{baseURL: fmt.Sprintf("http://%s:%s", host, port)} + return &Client{baseURL: fmt.Sprintf("http://%s:%s", host, port), log: log} } func (client *Client) Connect(remote string) error { _, err := client.httpVerb("POST", "/connect", url.Values{"peer": {remote}}) return err } + +type Logger interface { + Infof(string, ...interface{}) + Debugf(string, ...interface{}) +} diff --git a/prog/plugin/main.go b/prog/plugin/main.go index 2158d267..e0697e29 100644 --- a/prog/plugin/main.go +++ b/prog/plugin/main.go @@ -51,7 +51,7 @@ func main() { Log.Fatalf("unable to connect to docker: %s", err) } - weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR")) + weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log) Log.Println("Weave plugin", version, "Command line options:", os.Args[1:]) Log.Info(dockerClient.Info()) diff --git a/proxy/proxy.go b/proxy/proxy.go index 396e57a1..cbaac802 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -558,7 +558,7 @@ func (proxy *Proxy) getDNSDomain() string { if proxy.WithoutDNS { return "" } - weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR")) + weave := weaveapi.NewClient(os.Getenv("WEAVE_HTTP_ADDR"), Log) domain, _ := weave.DNSDomain() return domain }