ref(client): add a Get method helper

pull/419/head
Adam Reese 9 years ago
parent d91df39cba
commit fa6b34aa6b

@ -98,6 +98,14 @@ func (c *Client) agent() string {
return fmt.Sprintf("helm/%s", version.Version)
}
func (c *Client) Get(endpoint string, v interface{}) error {
return c.CallService(endpoint, "GET", &v, nil)
}
func (c *Client) Delete(endpoint string, v interface{}) error {
return c.CallService(endpoint, "DELETE", &v, nil)
}
// CallService is a low-level function for making an API call.
//
// This calls the service and then unmarshals the returned data into dest.

@ -102,5 +102,6 @@ func TestUserAgent(t *testing.T) {
}
}),
}
fc.setup().ListDeployments()
var nop struct{}
fc.setup().Get("/", &nop)
}

@ -32,11 +32,8 @@ import (
// ListDeployments lists the deployments in DM.
func (c *Client) ListDeployments() ([]string, error) {
var l []string
if err := c.CallService("deployments", "GET", &l, nil); err != nil {
return nil, err
}
return l, nil
err := c.Get("deployments", &l)
return l, err
}
// PostChart sends a chart to DM for deploying.
@ -94,19 +91,15 @@ func (c *Client) PostChart(filename, deployname string) (string, error) {
// GetDeployment retrieves the supplied deployment
func (c *Client) GetDeployment(name string) (*common.Deployment, error) {
var deployment *common.Deployment
if err := c.CallService(fancypath.Join("deployments", name), "GET", &deployment, nil); err != nil {
return nil, err
}
return deployment, nil
err := c.Get(fancypath.Join("deployments", name), &deployment)
return deployment, err
}
// DeleteDeployment deletes the supplied deployment
func (c *Client) DeleteDeployment(name string) (*common.Deployment, error) {
var deployment *common.Deployment
if err := c.CallService(filepath.Join("deployments", name), "DELETE", &deployment, nil); err != nil {
return nil, err
}
return deployment, nil
err := c.Delete(filepath.Join("deployments", name), &deployment)
return deployment, err
}
// PostDeployment posts a deployment object to the manager service.

Loading…
Cancel
Save