35 lines
649 B
Go
35 lines
649 B
Go
|
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
|
||
|
}
|