Skip to content

Commit

Permalink
isproxyset method, godoc update, travis config
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Jan 22, 2017
1 parent 469e981 commit e116316
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// Copyright (c) 2015-2017 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
//
Expand Down
10 changes: 8 additions & 2 deletions default.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// Copyright (c) 2015-2017 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
}
12 changes: 6 additions & 6 deletions request.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// Copyright (c) 2015-2017 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -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().
Expand All @@ -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().
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions resty_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// Copyright (c) 2015-2017 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 1 addition & 6 deletions retry_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// Copyright (c) 2015-2017 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

Expand All @@ -9,7 +9,6 @@ import (
"errors"
"net/http"
"reflect"
"runtime"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e116316

Please sign in to comment.