From 17143feb878f35c68f1db79bfa37b420ba38df75 Mon Sep 17 00:00:00 2001 From: Michelle Noorali Date: Thu, 17 Mar 2016 16:47:01 -0600 Subject: [PATCH] ref(helm): clean up callService --- cmd/helm/helm.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index b355b0c86..2f09be067 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -91,14 +91,17 @@ func NewClient(c *cli.Context) *client.Client { func callService(path, method, description string) ([]byte, error) { dmURL := "http://localhost:8080" - //dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" - var URL *url.URL - URL, err := url.Parse(dmURL) + //TODO: dmURL := "http://localhost:8001/api/v1/proxy/namespaces/dm/services/manager-service:manager" + client := &http.Client{} + url, err := formatPath(dmURL, path) + req, err := http.NewRequest(method, url.Path, nil) + if err != nil { + return nil, err + } + resp, err := client.Do(req) if err != nil { return nil, err } - URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(path, "/") - resp, err := http.Get(URL.Path) //TODO: change later if err != nil { return nil, err } @@ -110,3 +113,13 @@ func callService(path, method, description string) ([]byte, error) { } return body, nil } + +func formatPath(rawURL, route string) (*url.URL, error) { + var URL *url.URL + URL, err := url.Parse(rawURL) + if err != nil { + return nil, err + } + URL.Path = strings.TrimRight(URL.String(), "/") + "/" + strings.TrimLeft(route, "/") + return URL, nil +}