From e11631687b7d26c08fe1bfdf42cbff65be6f3b75 Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sat, 21 Jan 2017 16:35:56 -0800 Subject: [PATCH] isproxyset method, godoc update, travis config --- .travis.yml | 2 +- README.md | 5 +++-- client.go | 9 +++++++-- default.go | 10 ++++++++-- request.go | 12 ++++++------ resty_test.go | 6 +++--- retry_test.go | 7 +------ 7 files changed, 29 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index a308e3e7..f1b24951 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ install: - go get -v ./... script: - - go test -v ./... -coverprofile=coverage.txt -covermode=atomic + - go test -race -v ./... -coverprofile=coverage.txt -covermode=atomic after_success: - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index 0c9c3eab..3ba62df0 100644 --- a/README.md +++ b/README.md @@ -47,14 +47,15 @@ Go Resty first released on Sep 15, 2015 then go-resty grew gradually as a very h resty tested with Go `v1.2` and above. #### Included Batteries - * Redirect Policies - see [how to use in action](#redirect-policy) + * Redirect Policies - see [how to use](#redirect-policy) * NoRedirectPolicy * FlexibleRedirectPolicy * DomainCheckRedirectPolicy * etc. [more info](redirect.go) - * Retry Mechanism [reference](retry_test.go) + * Retry Mechanism [how to use](retry_test.go) * Backoff Retry * Conditional Retry + * SRV Record based request instead of Host URL [how to use](resty_test.go#L1412) * etc (upcoming - throw your idea's [here](https://github.com/go-resty/resty/issues)). ## Installation diff --git a/client.go b/client.go index 93893b71..4bd3bf7b 100644 --- a/client.go +++ b/client.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// Copyright (c) 2015-2017 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. // resty source code and usage is governed by a MIT style // license that can be found in the LICENSE file. @@ -214,7 +214,7 @@ func (c *Client) SetQueryParam(param, value string) *Client { return c } -// SetQueryParams method sets multiple paramaters and its values at one go in the client instance. +// SetQueryParams method sets multiple parameters and its values at one go in the client instance. // It will be formed as query string for the request. For example: `search=kitchen%20papers&size=large` // in the URL after `?` mark. These query params will be added to all the request raised from this // client instance. Also it can be overridden at request level Query Param options, @@ -700,6 +700,11 @@ func (c *Client) getTLSConfig() *tls.Config { return c.transport.TLSClientConfig } +// IsProxySet method returns the true if proxy is set on client otherwise false. +func (c *Client) IsProxySet() bool { + return c.proxyURL != nil +} + // // Response // diff --git a/default.go b/default.go index d96dd697..43738629 100644 --- a/default.go +++ b/default.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// Copyright (c) 2015-2017 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. // resty source code and usage is governed by a MIT style // license that can be found in the LICENSE file. @@ -99,7 +99,7 @@ func SetQueryParam(param, value string) *Client { return DefaultClient.SetQueryParam(param, value) } -// SetQueryParams method sets multiple paramaters and its value. See `Client.SetQueryParams` for more information. +// SetQueryParams method sets multiple parameters and its value. See `Client.SetQueryParams` for more information. func SetQueryParams(params map[string]string) *Client { return DefaultClient.SetQueryParams(params) } @@ -239,6 +239,12 @@ func SetCloseConnection(close bool) *Client { return DefaultClient.SetCloseConnection(close) } +// IsProxySet method returns the true if proxy is set on client otherwise false. +// See `Client.IsProxySet` for more information. +func IsProxySet() bool { + return DefaultClient.IsProxySet() +} + func init() { DefaultClient = New() } diff --git a/request.go b/request.go index 773a3499..1a4a88d3 100644 --- a/request.go +++ b/request.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// Copyright (c) 2015-2017 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. // resty source code and usage is governed by a MIT style // license that can be found in the LICENSE file. @@ -67,7 +67,7 @@ func (r *Request) SetQueryParam(param, value string) *Request { return r } -// SetQueryParams method sets multiple paramaters and its values at one go in the current request. +// SetQueryParams method sets multiple parameters and its values at one go in the current request. // It will be formed as query string for the request. // Example: `search=kitchen%20papers&size=large` in the URL after `?` mark. // resty.R(). @@ -85,7 +85,7 @@ func (r *Request) SetQueryParams(params map[string]string) *Request { return r } -// SetMultiValueQueryParams method sets multiple paramaters with multi-value +// SetMultiValueQueryParams method sets multiple parameters with multi-value // at one go in the current request. It will be formed as query string for the request. // Example: `status=pending&status=approved&status=open` in the URL after `?` mark. // resty.R(). @@ -140,7 +140,7 @@ func (r *Request) SetFormData(data map[string]string) *Request { return r } -// SetMultiValueFormData method sets multiple form paramaters with multi-value +// SetMultiValueFormData method sets multiple form parameters with multi-value // at one go in the current request. // resty.R(). // SetMultiValueFormData(url.Values{ @@ -320,7 +320,7 @@ func (r *Request) SetAuthToken(token string) *Request { } // SetOutput method sets the output file for current HTTP request. Current HTTP response will be -// saved into given file. It is similar to `curl -o` flag. Absoulte path or relative path can be used. +// saved into given file. It is similar to `curl -o` flag. Absolute path or relative path can be used. // If is it relative path then output file goes under the output directory, as mentioned // in the `Client.SetOutputDirectory`. // resty.R(). @@ -485,7 +485,7 @@ func (r *Request) fmtBodyString() (body string) { body = base64.StdEncoding.EncodeToString(b) } - if prtBodyBytes != nil { + if prtBodyBytes != nil && err == nil { body = string(prtBodyBytes) } } diff --git a/resty_test.go b/resty_test.go index b92064bf..b0242e7e 100644 --- a/resty_test.go +++ b/resty_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// Copyright (c) 2015-2017 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. // resty source code and usage is governed by a MIT style // license that can be found in the LICENSE file. @@ -948,11 +948,11 @@ func TestRawFileUploadByBody(t *testing.T) { func TestProxySetting(t *testing.T) { c := dc() - assertEqual(t, true, c.proxyURL == nil) + assertEqual(t, true, !c.IsProxySet()) assertEqual(t, true, (c.transport.Proxy == nil)) c.SetProxy("http://sampleproxy:8888") - assertEqual(t, true, c.proxyURL != nil) + assertEqual(t, true, c.IsProxySet()) assertEqual(t, true, (c.transport.Proxy == nil)) c.SetProxy("//not.a.user@%66%6f%6f.com:8888") diff --git a/retry_test.go b/retry_test.go index e475d3e1..19920e47 100644 --- a/retry_test.go +++ b/retry_test.go @@ -1,4 +1,4 @@ -// Copyright (c) 2015-2016 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// Copyright (c) 2015-2017 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. // resty source code and usage is governed by a MIT style // license that can be found in the LICENSE file. @@ -9,7 +9,6 @@ import ( "errors" "net/http" "reflect" - "runtime" "strconv" "testing" "time" @@ -175,10 +174,6 @@ func TestClientRetryGet(t *testing.T) { assertError(t, err) } -func GetFunctionName(i interface{}) string { - return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() -} - func TestClientRetryPost(t *testing.T) { ts := createPostServer(t) defer ts.Close()