callgraph/rancher/client.go

35 lines
649 B
Go
Raw Normal View History

2016-04-13 12:17:46 +00:00
package rancher
import (
"encoding/json"
"io/ioutil"
"net/http"
)
type Client struct {
Host, SecretKey, AccessKey string
client http.Client
}
func New(host, secretkey, accesskey string) Client {
return Client{host, secretkey, accesskey, http.Client{}}
}
func (c *Client) Get(url string, result interface{}) error {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
req.SetBasicAuth(c.AccessKey, c.SecretKey)
resp, err := c.client.Do(req)
if err != nil {
return err
}
body, err := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, result)
if err != nil {
return err
}
return nil
}