Move baseUrl usage up to httpVerb

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

No files matched your search

+2 -2
View File
@@ -8,11 +8,11 @@ import (
func (client *Client) RegisterWithDNS(ID string, fqdn string, ip string) error {
data := url.Values{}
data.Add("fqdn", fqdn)
_, err := httpVerb("PUT", fmt.Sprintf("%s/name/%s/%s", client.baseUrl, ID, ip), data)
_, err := client.httpVerb("PUT", fmt.Sprintf("/name/%s/%s", ID, ip), data)
return err
}
func (client *Client) DeregisterWithDNS(ID string, ip string) error {
_, err := httpVerb("DELETE", fmt.Sprintf("%s/name/%s/%s", client.baseUrl, ID, ip), nil)
_, err := client.httpVerb("DELETE", fmt.Sprintf("/name/%s/%s", ID, ip), nil)
return err
}
+2 -2
View File
@@ -6,7 +6,7 @@ import (
)
func (client *Client) ipamOp(ID string, op string) (*net.IPNet, error) {
ip, err := httpVerb(op, fmt.Sprintf("%s/ip/%s", client.baseUrl, ID), nil)
ip, err := client.httpVerb(op, fmt.Sprintf("/ip/%s", ID), nil)
if err != nil {
return nil, err
}
@@ -31,7 +31,7 @@ func (client *Client) ReleaseIP(ID string) error {
}
func (client *Client) DefaultSubnet() (*net.IPNet, error) {
cidr, err := httpVerb("GET", fmt.Sprintf("%s/ipinfo/defaultsubnet", client.baseUrl), nil)
cidr, err := client.httpVerb("GET", fmt.Sprintf("/ipinfo/defaultsubnet"), nil)
if err != nil {
return nil, err
}
+3 -2
View File
@@ -20,7 +20,8 @@ type Client struct {
baseUrl string
}
func httpVerb(verb string, url string, values url.Values) (string, error) {
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)
var body io.Reader
if values != nil {
@@ -54,6 +55,6 @@ func NewClient(addr string) *Client {
}
func (client *Client) Connect(remote string) error {
_, err := httpVerb("POST", client.baseUrl+"/connect", url.Values{"peer": {remote}})
_, err := client.httpVerb("POST", "/connect", url.Values{"peer": {remote}})
return err
}