Resolve weave IP every time we need it, in case it changed

This commit is contained in:
Bryan Boreham committed 2015-12-08 16:59:34 +00:00
1 parent a6f07fbaac
commit ecd93bbfe4
3 files changed
+26 -51

No files matched your search

+14 -1
View File
@@ -18,10 +18,19 @@ const (
type Client struct {
baseUrl string
resolve func() (string, error)
}
func (client *Client) httpVerb(verb string, url string, values url.Values) (string, error) {
url = client.baseUrl + url
baseUrl := client.baseUrl
if client.resolve != nil {
addr, err := client.resolve()
if err != nil {
return "", err
}
baseUrl = fmt.Sprintf("http://%s:%d", addr, WeaveHttpPort)
}
url = baseUrl + url
Log.Debugf("weave %s to %s with %v", verb, url, values)
var body io.Reader
if values != nil {
@@ -54,6 +63,10 @@ func NewClient(addr string) *Client {
return &Client{baseUrl: fmt.Sprintf("http://%s:%d", addr, WeaveHttpPort)}
}
func NewClientWithResolver(resolver func() (string, error)) *Client {
return &Client{resolve: resolver}
}
func (client *Client) Connect(remote string) error {
_, err := client.httpVerb("POST", "/connect", url.Values{"peer": {remote}})
return err