From ad1b7d9756217493efc33806bf09b15794865de0 Mon Sep 17 00:00:00 2001 From: gongweibao Date: Fri, 2 Jun 2017 15:56:26 +0800 Subject: [PATCH 1/5] change restclient --- go/paddlecloud/restclient.go | 90 +++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/go/paddlecloud/restclient.go b/go/paddlecloud/restclient.go index 04daea66..6bda21ca 100644 --- a/go/paddlecloud/restclient.go +++ b/go/paddlecloud/restclient.go @@ -14,7 +14,15 @@ import ( // HTTPOK is ok status of http api call const HTTPOK = "200 OK" -var httpTransport = &http.Transport{} +type RestClient struct { + client *http.Client +} + +// NewRestClient returns a new RestClient struct. +func NewRestClient() *RestClient { + client := http.Client{Transport: &http.Transport{}} + return &RestClient{client: &client} +} func makeRequest(uri string, method string, body io.Reader, contentType string, query map[string]string, @@ -57,9 +65,8 @@ func makeRequestToken(uri string, method string, body io.Reader, // NOTE: add other request makers if we need other auth methods -func getResponse(req *http.Request) ([]byte, error) { - client := &http.Client{Transport: httpTransport} - resp, err := client.Do(req) +func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { + resp, err := p.client.Do(req) if err != nil { return []byte{}, err } @@ -72,34 +79,34 @@ func getResponse(req *http.Request) ([]byte, error) { } // GetCall make a GET call to targetURL with k-v params of query -func GetCall(targetURL string, query map[string]string) ([]byte, error) { +func (p *RestClient) GetCall(targetURL string, query map[string]string) ([]byte, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return []byte{}, err } - return getResponse(req) + return p.getResponse(req) } // PostCall make a POST call to targetURL with a json body -func PostCall(targetURL string, jsonString []byte) ([]byte, error) { +func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } - return getResponse(req) + return p.getResponse(req) } // DeleteCall make a DELETE call to targetURL with a json body -func DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { +func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } - return getResponse(req) + return p.getResponse(req) } // PostFile make a POST call to HTTP server to upload a file -func PostFile(targetURL string, filename string) ([]byte, error) { +func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) { bodyBuf := &bytes.Buffer{} bodyWriter := multipart.NewWriter(bodyBuf) @@ -130,5 +137,64 @@ func PostFile(targetURL string, filename string) ([]byte, error) { if err != nil { return []byte{}, err } - return getResponse(req) + return p.getResponse(req) +} + +// PostChunkData makes a POST call to HTTP server to upload chunkdata +func (p *RestClient) PostChunk(targetURL string, + chunkName string, reader io.Reader, len int64, boundary string) ([]byte, error) { + body := &bytes.Buffer{} + writer := multipart.NewWriter(body) + if err := writer.SetBoundary(boundary); err != nil { + return nil, err + } + + part, err := writer.CreateFormFile("chunk", chunkName) + if err != nil { + return nil, err + } + + _, err = io.CopyN(part, reader, len) + if err != nil { + return nil, err + } + + contentType := writer.FormDataContentType() + writer.Close() + + req, err := makeRequestToken(targetURL, "POST", body, contentType, nil) + if err != nil { + return []byte{}, err + } + + return p.getResponse(req) +} + +// GetChunkData makes a GET call to HTTP server to download chunk data +func (p *RestClient) GetChunk(targetURL string, + query map[string]string) (*http.Response, error) { + req, err := makeRequestToken(targetURL, "GET", nil, "", query) + if err != nil { + return nil, err + } + + return p.client.Do(req) +} + +// GetCall makes a GET call to targetURL with k-v params of query. +func GetCall(targetURL string, query map[string]string) ([]byte, error) { + client := NewRestClient() + return client.GetCall(targetURL, query) +} + +// PostCall makes a POST call to targetURL with a json body. +func PostCall(targetURL string, jsonString []byte) ([]byte, error) { + client := NewRestClient() + return client.PostCall(targetURL, jsonString) +} + +// DeleteCall makes a DELETE call to targetURL with a json body. +func DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { + client := NewRestClient() + return client.DeleteCall(targetURL, jsonString) } From fb4d225ad625e4ca5f7ab223fb1ca2a3ebd13a32 Mon Sep 17 00:00:00 2001 From: gongweibao Date: Fri, 2 Jun 2017 17:33:56 +0800 Subject: [PATCH 2/5] change map to string --- go/paddlecloud/restclient.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/go/paddlecloud/restclient.go b/go/paddlecloud/restclient.go index 6bda21ca..f49286d7 100644 --- a/go/paddlecloud/restclient.go +++ b/go/paddlecloud/restclient.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "mime/multipart" "net/http" + "net/url" "os" ) @@ -25,7 +26,7 @@ func NewRestClient() *RestClient { } func makeRequest(uri string, method string, body io.Reader, - contentType string, query map[string]string, + contentType string, query string, authHeader map[string]string) (*http.Request, error) { req, err := http.NewRequest(method, uri, nil) if err != nil { @@ -42,17 +43,13 @@ func makeRequest(uri string, method string, body io.Reader, req.Header.Set(k, v) } - q := req.URL.Query() - for k, v := range query { - q.Add(k, v) - } - req.URL.RawQuery = q.Encode() + req.URL.RawQuery = query return req, nil } // makeRequestToken use client token to make a authorized request func makeRequestToken(uri string, method string, body io.Reader, - contentType string, query map[string]string) (*http.Request, error) { + contentType string, query string) (*http.Request, error) { // get client token token, err := token() if err != nil { @@ -78,8 +75,8 @@ func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { return ioutil.ReadAll(resp.Body) } -// GetCall make a GET call to targetURL with k-v params of query -func (p *RestClient) GetCall(targetURL string, query map[string]string) ([]byte, error) { +// GetCall make a GET call to targetURL with query +func (p *RestClient) GetCall(targetURL string, query string) ([]byte, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return []byte{}, err @@ -89,7 +86,7 @@ func (p *RestClient) GetCall(targetURL string, query map[string]string) ([]byte, // PostCall make a POST call to targetURL with a json body func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, error) { - req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", nil) + req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", "") if err != nil { return []byte{}, err } @@ -98,7 +95,7 @@ func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, erro // DeleteCall make a DELETE call to targetURL with a json body func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { - req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", nil) + req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", "") if err != nil { return []byte{}, err } @@ -133,7 +130,7 @@ func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) contentType := bodyWriter.FormDataContentType() bodyWriter.Close() - req, err := makeRequestToken(targetURL, "POST", bodyBuf, contentType, nil) + req, err := makeRequestToken(targetURL, "POST", bodyBuf, contentType, "") if err != nil { return []byte{}, err } @@ -162,7 +159,7 @@ func (p *RestClient) PostChunk(targetURL string, contentType := writer.FormDataContentType() writer.Close() - req, err := makeRequestToken(targetURL, "POST", body, contentType, nil) + req, err := makeRequestToken(targetURL, "POST", body, contentType, "") if err != nil { return []byte{}, err } @@ -172,7 +169,7 @@ func (p *RestClient) PostChunk(targetURL string, // GetChunkData makes a GET call to HTTP server to download chunk data func (p *RestClient) GetChunk(targetURL string, - query map[string]string) (*http.Response, error) { + query string) (*http.Response, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return nil, err @@ -184,7 +181,13 @@ func (p *RestClient) GetChunk(targetURL string, // GetCall makes a GET call to targetURL with k-v params of query. func GetCall(targetURL string, query map[string]string) ([]byte, error) { client := NewRestClient() - return client.GetCall(targetURL, query) + + q := url.Values{} + for k, v := range query { + q.Add(k, v) + } + + return client.GetCall(targetURL, q.Encode()) } // PostCall makes a POST call to targetURL with a json body. From 3c42948d578c32d2defc3a5f9d4eaf8e90b955c1 Mon Sep 17 00:00:00 2001 From: gongweibao Date: Fri, 2 Jun 2017 17:42:21 +0800 Subject: [PATCH 3/5] fix by comments --- go/paddlecloud/restclient.go | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/go/paddlecloud/restclient.go b/go/paddlecloud/restclient.go index f49286d7..157c6dba 100644 --- a/go/paddlecloud/restclient.go +++ b/go/paddlecloud/restclient.go @@ -12,7 +12,7 @@ import ( "os" ) -// HTTPOK is ok status of http api call +// HTTPOK is ok status of http api call. const HTTPOK = "200 OK" type RestClient struct { @@ -32,7 +32,7 @@ func makeRequest(uri string, method string, body io.Reader, if err != nil { return nil, err } - // default contentType is application/json + // default contentType is application/json. if len(contentType) == 0 { req.Header.Set("Content-Type", "application/json") } else { @@ -47,7 +47,7 @@ func makeRequest(uri string, method string, body io.Reader, return req, nil } -// makeRequestToken use client token to make a authorized request +// makeRequestToken use client token to make a authorized request. func makeRequestToken(uri string, method string, body io.Reader, contentType string, query string) (*http.Request, error) { // get client token @@ -60,7 +60,7 @@ func makeRequestToken(uri string, method string, body io.Reader, return makeRequest(uri, method, body, contentType, query, authHeader) } -// NOTE: add other request makers if we need other auth methods +// NOTE: add other request makers if we need other auth methods. func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { resp, err := p.client.Do(req) @@ -71,11 +71,11 @@ func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { if resp.Status != HTTPOK { return []byte{}, errors.New("server error: " + resp.Status) } - // FIXME: add more resp.Status checks + // FIXME: add more resp.Status checks. return ioutil.ReadAll(resp.Body) } -// GetCall make a GET call to targetURL with query +// GetCall make a GET call to targetURL with query. func (p *RestClient) GetCall(targetURL string, query string) ([]byte, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { @@ -84,7 +84,7 @@ func (p *RestClient) GetCall(targetURL string, query string) ([]byte, error) { return p.getResponse(req) } -// PostCall make a POST call to targetURL with a json body +// PostCall make a POST call to targetURL with a json body. func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", "") if err != nil { @@ -93,7 +93,7 @@ func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, erro return p.getResponse(req) } -// DeleteCall make a DELETE call to targetURL with a json body +// DeleteCall make a DELETE call to targetURL with a json body. func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", "") if err != nil { @@ -102,7 +102,7 @@ func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, er return p.getResponse(req) } -// PostFile make a POST call to HTTP server to upload a file +// PostFile make a POST call to HTTP server to upload a file. func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) { bodyBuf := &bytes.Buffer{} bodyWriter := multipart.NewWriter(bodyBuf) @@ -137,7 +137,7 @@ func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) return p.getResponse(req) } -// PostChunkData makes a POST call to HTTP server to upload chunkdata +// PostChunkData makes a POST call to HTTP server to upload chunkdata. func (p *RestClient) PostChunk(targetURL string, chunkName string, reader io.Reader, len int64, boundary string) ([]byte, error) { body := &bytes.Buffer{} @@ -167,7 +167,7 @@ func (p *RestClient) PostChunk(targetURL string, return p.getResponse(req) } -// GetChunkData makes a GET call to HTTP server to download chunk data +// GetChunkData makes a GET call to HTTP server to download chunk data. func (p *RestClient) GetChunk(targetURL string, query string) (*http.Response, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) @@ -178,26 +178,24 @@ func (p *RestClient) GetChunk(targetURL string, return p.client.Do(req) } +var DefaultClient = NewRestClient() + // GetCall makes a GET call to targetURL with k-v params of query. func GetCall(targetURL string, query map[string]string) ([]byte, error) { - client := NewRestClient() - q := url.Values{} for k, v := range query { q.Add(k, v) } - return client.GetCall(targetURL, q.Encode()) + return DefaultClient.GetCall(targetURL, q.Encode()) } // PostCall makes a POST call to targetURL with a json body. func PostCall(targetURL string, jsonString []byte) ([]byte, error) { - client := NewRestClient() - return client.PostCall(targetURL, jsonString) + return DefaultClient.PostCall(targetURL, jsonString) } // DeleteCall makes a DELETE call to targetURL with a json body. func DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { - client := NewRestClient() - return client.DeleteCall(targetURL, jsonString) + return DefaultClient.DeleteCall(targetURL, jsonString) } From ea31b78da2fcaab46bd444037380fd7de7410182 Mon Sep 17 00:00:00 2001 From: gongweibao Date: Fri, 2 Jun 2017 18:12:09 +0800 Subject: [PATCH 4/5] change to url.Values{} --- go/paddlecloud/restclient.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/go/paddlecloud/restclient.go b/go/paddlecloud/restclient.go index 157c6dba..a2b3f446 100644 --- a/go/paddlecloud/restclient.go +++ b/go/paddlecloud/restclient.go @@ -26,7 +26,7 @@ func NewRestClient() *RestClient { } func makeRequest(uri string, method string, body io.Reader, - contentType string, query string, + contentType string, query url.Values, authHeader map[string]string) (*http.Request, error) { req, err := http.NewRequest(method, uri, nil) if err != nil { @@ -43,13 +43,15 @@ func makeRequest(uri string, method string, body io.Reader, req.Header.Set(k, v) } - req.URL.RawQuery = query + if query != nil { + req.URL.RawQuery = query.Encode() + } return req, nil } // makeRequestToken use client token to make a authorized request. func makeRequestToken(uri string, method string, body io.Reader, - contentType string, query string) (*http.Request, error) { + contentType string, query url.Values) (*http.Request, error) { // get client token token, err := token() if err != nil { @@ -76,7 +78,7 @@ func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { } // GetCall make a GET call to targetURL with query. -func (p *RestClient) GetCall(targetURL string, query string) ([]byte, error) { +func (p *RestClient) GetCall(targetURL string, query url.Values) ([]byte, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return []byte{}, err @@ -86,7 +88,7 @@ func (p *RestClient) GetCall(targetURL string, query string) ([]byte, error) { // PostCall make a POST call to targetURL with a json body. func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, error) { - req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", "") + req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } @@ -95,7 +97,7 @@ func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, erro // DeleteCall make a DELETE call to targetURL with a json body. func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { - req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", "") + req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } @@ -130,7 +132,7 @@ func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) contentType := bodyWriter.FormDataContentType() bodyWriter.Close() - req, err := makeRequestToken(targetURL, "POST", bodyBuf, contentType, "") + req, err := makeRequestToken(targetURL, "POST", bodyBuf, contentType, nil) if err != nil { return []byte{}, err } @@ -159,7 +161,7 @@ func (p *RestClient) PostChunk(targetURL string, contentType := writer.FormDataContentType() writer.Close() - req, err := makeRequestToken(targetURL, "POST", body, contentType, "") + req, err := makeRequestToken(targetURL, "POST", body, contentType, nil) if err != nil { return []byte{}, err } @@ -169,7 +171,7 @@ func (p *RestClient) PostChunk(targetURL string, // GetChunkData makes a GET call to HTTP server to download chunk data. func (p *RestClient) GetChunk(targetURL string, - query string) (*http.Response, error) { + query url.Values) (*http.Response, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return nil, err @@ -187,7 +189,7 @@ func GetCall(targetURL string, query map[string]string) ([]byte, error) { q.Add(k, v) } - return DefaultClient.GetCall(targetURL, q.Encode()) + return DefaultClient.GetCall(targetURL, q) } // PostCall makes a POST call to targetURL with a json body. From 94e35bc287737b528f370dcdd15666298a67b65e Mon Sep 17 00:00:00 2001 From: gongweibao Date: Fri, 2 Jun 2017 19:24:01 +0800 Subject: [PATCH 5/5] fix by comments --- go/paddlecloud/get.go | 5 +-- go/paddlecloud/logs.go | 10 +++--- go/paddlecloud/restclient.go | 60 +++++++++--------------------------- 3 files changed, 24 insertions(+), 51 deletions(-) diff --git a/go/paddlecloud/get.go b/go/paddlecloud/get.go index f2b8d17f..e43a4212 100644 --- a/go/paddlecloud/get.go +++ b/go/paddlecloud/get.go @@ -5,6 +5,7 @@ import ( "encoding/json" "flag" "fmt" + "net/url" "os" "strings" "text/tabwriter" @@ -60,8 +61,8 @@ func (p *GetCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{ } func workers(jobname string) error { - queryMap := make(map[string]string) - queryMap["jobname"] = jobname + var queryMap url.Values + queryMap.Add("jobname", jobname) respBody, err := GetCall(config.ActiveConfig.Endpoint+"/api/v1/workers/", queryMap) if err != nil { fmt.Fprintf(os.Stderr, "error getting workers: %v\n", err) diff --git a/go/paddlecloud/logs.go b/go/paddlecloud/logs.go index 3110d7ed..11e372d1 100644 --- a/go/paddlecloud/logs.go +++ b/go/paddlecloud/logs.go @@ -5,6 +5,7 @@ import ( "encoding/json" "flag" "fmt" + "net/url" "os" "strconv" @@ -43,11 +44,12 @@ func (p *LogsCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface f.Usage() return subcommands.ExitFailure } - queryMap := make(map[string]string) - queryMap["n"] = strconv.FormatInt(int64(p.n), 10) - queryMap["w"] = p.w - queryMap["jobname"] = f.Arg(0) + var queryMap url.Values + queryMap.Add("n", strconv.FormatInt(int64(p.n), 10)) + queryMap.Add("w", p.w) + queryMap.Add("jobname", f.Arg(0)) + respBody, err := GetCall(config.ActiveConfig.Endpoint+"/api/v1/logs", queryMap) if err != nil { fmt.Fprintf(os.Stderr, "call paddle cloud error %v", err) diff --git a/go/paddlecloud/restclient.go b/go/paddlecloud/restclient.go index a2b3f446..85dcab58 100644 --- a/go/paddlecloud/restclient.go +++ b/go/paddlecloud/restclient.go @@ -15,15 +15,7 @@ import ( // HTTPOK is ok status of http api call. const HTTPOK = "200 OK" -type RestClient struct { - client *http.Client -} - -// NewRestClient returns a new RestClient struct. -func NewRestClient() *RestClient { - client := http.Client{Transport: &http.Transport{}} - return &RestClient{client: &client} -} +var httpClient = &http.Client{Transport: &http.Transport{}} func makeRequest(uri string, method string, body io.Reader, contentType string, query url.Values, @@ -64,8 +56,8 @@ func makeRequestToken(uri string, method string, body io.Reader, // NOTE: add other request makers if we need other auth methods. -func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { - resp, err := p.client.Do(req) +func getResponse(req *http.Request) ([]byte, error) { + resp, err := httpClient.Do(req) if err != nil { return []byte{}, err } @@ -78,34 +70,34 @@ func (p *RestClient) getResponse(req *http.Request) ([]byte, error) { } // GetCall make a GET call to targetURL with query. -func (p *RestClient) GetCall(targetURL string, query url.Values) ([]byte, error) { +func GetCall(targetURL string, query url.Values) ([]byte, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return []byte{}, err } - return p.getResponse(req) + return getResponse(req) } // PostCall make a POST call to targetURL with a json body. -func (p *RestClient) PostCall(targetURL string, jsonString []byte) ([]byte, error) { +func PostCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "POST", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } - return p.getResponse(req) + return getResponse(req) } // DeleteCall make a DELETE call to targetURL with a json body. -func (p *RestClient) DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { +func DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { req, err := makeRequestToken(targetURL, "DELETE", bytes.NewBuffer(jsonString), "", nil) if err != nil { return []byte{}, err } - return p.getResponse(req) + return getResponse(req) } // PostFile make a POST call to HTTP server to upload a file. -func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) { +func PostFile(targetURL string, filename string) ([]byte, error) { bodyBuf := &bytes.Buffer{} bodyWriter := multipart.NewWriter(bodyBuf) @@ -136,11 +128,11 @@ func (p *RestClient) PostFile(targetURL string, filename string) ([]byte, error) if err != nil { return []byte{}, err } - return p.getResponse(req) + return getResponse(req) } // PostChunkData makes a POST call to HTTP server to upload chunkdata. -func (p *RestClient) PostChunk(targetURL string, +func PostChunk(targetURL string, chunkName string, reader io.Reader, len int64, boundary string) ([]byte, error) { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -166,38 +158,16 @@ func (p *RestClient) PostChunk(targetURL string, return []byte{}, err } - return p.getResponse(req) + return getResponse(req) } // GetChunkData makes a GET call to HTTP server to download chunk data. -func (p *RestClient) GetChunk(targetURL string, +func GetChunk(targetURL string, query url.Values) (*http.Response, error) { req, err := makeRequestToken(targetURL, "GET", nil, "", query) if err != nil { return nil, err } - return p.client.Do(req) -} - -var DefaultClient = NewRestClient() - -// GetCall makes a GET call to targetURL with k-v params of query. -func GetCall(targetURL string, query map[string]string) ([]byte, error) { - q := url.Values{} - for k, v := range query { - q.Add(k, v) - } - - return DefaultClient.GetCall(targetURL, q) -} - -// PostCall makes a POST call to targetURL with a json body. -func PostCall(targetURL string, jsonString []byte) ([]byte, error) { - return DefaultClient.PostCall(targetURL, jsonString) -} - -// DeleteCall makes a DELETE call to targetURL with a json body. -func DeleteCall(targetURL string, jsonString []byte) ([]byte, error) { - return DefaultClient.DeleteCall(targetURL, jsonString) + return httpClient.Do(req) }