From fa6b34aa6b0c31e76b2d6f2362b03ad8d9d28b33 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 17 Mar 2016 16:41:30 -0600 Subject: [PATCH] ref(client): add a Get method helper --- pkg/client/client.go | 8 ++++++++ pkg/client/client_test.go | 3 ++- pkg/client/deployments.go | 19 ++++++------------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index 33c8f7490..c245207af 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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. diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index bd729b43f..f6e48ac11 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -102,5 +102,6 @@ func TestUserAgent(t *testing.T) { } }), } - fc.setup().ListDeployments() + var nop struct{} + fc.setup().Get("/", &nop) } diff --git a/pkg/client/deployments.go b/pkg/client/deployments.go index 9e961fbb9..27ef4c452 100644 --- a/pkg/client/deployments.go +++ b/pkg/client/deployments.go @@ -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.