From 145722a0b78ae45e10ce82e0eaad81f2bd3a134a Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Sun, 17 Sep 2023 17:10:06 -0700 Subject: [PATCH] docs: update godoc, version bump, and readme --- README.md | 8 ++++---- client.go | 46 +++++++++++++++++++++++++++++++++------------- client_test.go | 6 +++--- redirect.go | 5 +++-- request.go | 6 +++++- request_test.go | 2 +- resty.go | 2 +- 7 files changed, 50 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 54b50e7c..fce728d0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

Features section describes in detail about Resty capabilities

-

Build Status Code Coverage Go Report Card Release Version GoDoc License Mentioned in Awesome Go

+

Build Status Code Coverage Go Report Card Release Version GoDoc License Mentioned in Awesome Go

Resty Communication Channels

@@ -13,7 +13,7 @@ ## News - * v2.7.0 [released](https://github.com/go-resty/resty/releases/tag/v2.7.0) and tagged on Nov 03, 2021. + * v2.8.0 [released](https://github.com/go-resty/resty/releases/tag/v2.8.0) and tagged on Sep 17, 2023. * v2.0.0 [released](https://github.com/go-resty/resty/releases/tag/v2.0.0) and tagged on Jul 16, 2019. * v1.12.0 [released](https://github.com/go-resty/resty/releases/tag/v1.12.0) and tagged on Feb 27, 2019. * v1.0 released and tagged on Sep 25, 2017. - Resty's first version was released on Sep 15, 2015 then it grew gradually as a very handy and helpful library. Its been a two years since first release. I'm very thankful to Resty users and its [contributors](https://github.com/go-resty/resty/graphs/contributors). @@ -477,7 +477,7 @@ resp, err := client.R(). client := resty.New() // Setting output directory path, If directory not exists then resty creates one! -// This is optional one, if you're planning using absoule path in +// This is optional one, if you're planning using absolute path in // `Request.SetOutput` and can used together. client.SetOutputDirectory("/Users/jeeva/Downloads") @@ -822,7 +822,7 @@ client.SetCookies(cookies) client.SetQueryParam("user_id", "00001") client.SetQueryParams(map[string]string{ // sample of those who use this manner "api_key": "api-key-here", - "api_secert": "api-secert", + "api_secret": "api-secret", }) client.R().SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more") diff --git a/client.go b/client.go index 4122e935..b6c4a2e8 100644 --- a/client.go +++ b/client.go @@ -327,7 +327,7 @@ func (c *Client) SetQueryParams(params map[string]string) *Client { } // SetFormData method sets Form parameters and their values in the client instance. -// It's applicable only HTTP method `POST` and `PUT` and requets content type would be set as +// It's applicable only HTTP method `POST` and `PUT` and request content type would be set as // `application/x-www-form-urlencoded`. These form data will be added to all the request raised from // this client instance. Also it can be overridden at request level form data. // @@ -352,7 +352,7 @@ func (c *Client) SetFormData(data map[string]string) *Client { // // client.SetBasicAuth("go-resty", "welcome") // -// This basic auth information gets added to all the request rasied from this client instance. +// This basic auth information gets added to all the request raised from this client instance. // Also it can be overridden or set one at the request level is supported. // // See `Request.SetBasicAuth`. @@ -370,7 +370,7 @@ func (c *Client) SetBasicAuth(username, password string) *Client { // // client.SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F") // -// This auth token gets added to all the requests rasied from this client instance. +// This auth token gets added to all the requests raised from this client instance. // Also it can be overridden or set one at the request level is supported. // // See `Request.SetAuthToken`. @@ -387,7 +387,7 @@ func (c *Client) SetAuthToken(token string) *Client { // // client.SetAuthScheme("OAuth") // -// This auth scheme gets added to all the requests rasied from this client instance. +// This auth scheme gets added to all the requests raised from this client instance. // Also it can be overridden or set one at the request level is supported. // // Information about auth schemes can be found in RFC7235 which is linked to below @@ -476,7 +476,7 @@ func (c *Client) OnBeforeRequest(m RequestMiddleware) *Client { // OnAfterResponse method appends response middleware into the after response chain. // Once we receive response from host server, default Resty response middleware -// gets applied and then user assigened response middlewares applied. +// gets applied and then user assigned response middlewares applied. // // client.OnAfterResponse(func(c *resty.Client, r *resty.Response) error { // // Now you have access to Client and Response instance @@ -506,7 +506,7 @@ func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client { // }) // // Out of the OnSuccess, OnError, OnInvalid, OnPanic callbacks, exactly one -// set will be invoked for each call to Request.Execute() that comletes. +// set will be invoked for each call to Request.Execute() that completes. func (c *Client) OnError(h ErrorHook) *Client { c.errorHooks = append(c.errorHooks, h) return c @@ -516,29 +516,35 @@ func (c *Client) OnError(h ErrorHook) *Client { // succeeds. This is called after all retries have been attempted (if any). // // Out of the OnSuccess, OnError, OnInvalid, OnPanic callbacks, exactly one -// set will be invoked for each call to Request.Execute() that comletes. +// set will be invoked for each call to Request.Execute() that completes. +// +// Since v2.8.0 func (c *Client) OnSuccess(h SuccessHook) *Client { c.successHooks = append(c.successHooks, h) return c } -// OnInvalid method adds a callback that will be run whever a request execution +// OnInvalid method adds a callback that will be run whenever a request execution // fails before it starts because the request is invalid. // // Out of the OnSuccess, OnError, OnInvalid, OnPanic callbacks, exactly one -// set will be invoked for each call to Request.Execute() that comletes. +// set will be invoked for each call to Request.Execute() that completes. +// +// Since v2.8.0 func (c *Client) OnInvalid(h ErrorHook) *Client { c.invalidHooks = append(c.invalidHooks, h) return c } -// OnPanic method adds a callback that will be run whever a request execution +// OnPanic method adds a callback that will be run whenever a request execution // panics. // // Out of the OnSuccess, OnError, OnInvalid, OnPanic callbacks, exactly one // set will be invoked for each call to Request.Execute() that completes. // If an OnSuccess, OnError, or OnInvalid callback panics, then the exactly // one rule can be violated. +// +// Since v2.8.0 func (c *Client) OnPanic(h ErrorHook) *Client { c.panicHooks = append(c.panicHooks, h) return c @@ -547,7 +553,7 @@ func (c *Client) OnPanic(h ErrorHook) *Client { // SetPreRequestHook method sets the given pre-request function into resty client. // It is called right before the request is fired. // -// Note: Only one pre-request hook can be registered. Use `client.OnBeforeRequest` for mutilple. +// Note: Only one pre-request hook can be registered. Use `client.OnBeforeRequest` for multiple. func (c *Client) SetPreRequestHook(h PreRequestHook) *Client { if c.preReqHook != nil { c.log.Warnf("Overwriting an existing pre-request hook: %s", functionName(h)) @@ -657,7 +663,7 @@ func (c *Client) SetError(err interface{}) *Client { return c } -// SetRedirectPolicy method sets the client redirect poilicy. Resty provides ready to use +// SetRedirectPolicy method sets the client redirect policy. Resty provides ready to use // redirect policies. Wanna create one for yourself refer to `redirect.go`. // // client.SetRedirectPolicy(FlexibleRedirectPolicy(20)) @@ -718,6 +724,8 @@ func (c *Client) SetRetryAfter(callback RetryAfterFunc) *Client { // SetJSONMarshaler method sets the JSON marshaler function to marshal the request body. // By default, Resty uses `encoding/json` package to marshal the request body. +// +// Since v2.8.0 func (c *Client) SetJSONMarshaler(marshaler func(v interface{}) ([]byte, error)) *Client { c.JSONMarshal = marshaler return c @@ -725,6 +733,8 @@ func (c *Client) SetJSONMarshaler(marshaler func(v interface{}) ([]byte, error)) // SetJSONUnmarshaler method sets the JSON unmarshaler function to unmarshal the response body. // By default, Resty uses `encoding/json` package to unmarshal the response body. +// +// Since v2.8.0 func (c *Client) SetJSONUnmarshaler(unmarshaler func(data []byte, v interface{}) error) *Client { c.JSONUnmarshal = unmarshaler return c @@ -732,6 +742,8 @@ func (c *Client) SetJSONUnmarshaler(unmarshaler func(data []byte, v interface{}) // SetXMLMarshaler method sets the XML marshaler function to marshal the request body. // By default, Resty uses `encoding/xml` package to marshal the request body. +// +// Since v2.8.0 func (c *Client) SetXMLMarshaler(marshaler func(v interface{}) ([]byte, error)) *Client { c.XMLMarshal = marshaler return c @@ -739,6 +751,8 @@ func (c *Client) SetXMLMarshaler(marshaler func(v interface{}) ([]byte, error)) // SetXMLUnmarshaler method sets the XML unmarshaler function to unmarshal the response body. // By default, Resty uses `encoding/xml` package to unmarshal the response body. +// +// Since v2.8.0 func (c *Client) SetXMLUnmarshaler(unmarshaler func(data []byte, v interface{}) error) *Client { c.XMLUnmarshal = unmarshaler return c @@ -916,7 +930,7 @@ func (c *Client) SetOutputDirectory(dirPath string) *Client { // - It overwrites the Resty client transport instance and it's configurations. // // transport := &http.Transport{ -// // somthing like Proxying to httptest.Server, etc... +// // something like Proxying to httptest.Server, etc... // Proxy: func(req *http.Request) (*url.URL, error) { // return url.Parse(server.URL) // }, @@ -1022,6 +1036,8 @@ func (c *Client) SetPathParams(params map[string]string) *Client { // // Also it can be overridden at request level Path Params options, // see `Request.SetPathParam` or `Request.SetPathParams`. +// +// Since v2.8.0 func (c *Client) SetRawPathParam(param, value string) *Client { c.RawPathParams[param] = value return c @@ -1045,6 +1061,8 @@ func (c *Client) SetRawPathParam(param, value string) *Client { // // Also it can be overridden at request level Path Params options, // see `Request.SetPathParam` or `Request.SetPathParams`. +// +// Since v2.8.0 func (c *Client) SetRawPathParams(params map[string]string) *Client { for p, v := range params { c.SetRawPathParam(p, v) @@ -1209,6 +1227,8 @@ func (c *Client) tlsConfig() (*tls.Config, error) { // Transport method returns `*http.Transport` currently in use or error // in case currently used `transport` is not a `*http.Transport`. +// +// Since v2.8.0 become exported method. func (c *Client) Transport() (*http.Transport, error) { if transport, ok := c.httpClient.Transport.(*http.Transport); ok { return transport, nil diff --git a/client_test.go b/client_test.go index 966e029a..da098fbc 100644 --- a/client_test.go +++ b/client_test.go @@ -711,12 +711,12 @@ func TestLogCallbacks(t *testing.T) { c.outputLogTo(&lgr) c.OnRequestLog(func(r *RequestLog) error { - // masking authorzation header + // masking authorization header r.Header.Set("Authorization", "Bearer *******************************") return nil }) c.OnResponseLog(func(r *ResponseLog) error { - r.Header.Add("X-Debug-Resposne-Log", "Modified :)") + r.Header.Add("X-Debug-Response-Log", "Modified :)") r.Body += "\nModified the response body content" return nil }) @@ -734,7 +734,7 @@ func TestLogCallbacks(t *testing.T) { // Validating debug log updates logInfo := lgr.String() assertEqual(t, true, strings.Contains(logInfo, "Bearer *******************************")) - assertEqual(t, true, strings.Contains(logInfo, "X-Debug-Resposne-Log")) + assertEqual(t, true, strings.Contains(logInfo, "X-Debug-Response-Log")) assertEqual(t, true, strings.Contains(logInfo, "Modified the response body content")) // Error scenario diff --git a/redirect.go b/redirect.go index fdca9fe6..ed58d735 100644 --- a/redirect.go +++ b/redirect.go @@ -13,6 +13,7 @@ import ( ) var ( + // Since v2.8.0 ErrAutoRedirectDisabled = errors.New("auto redirect is disabled") ) @@ -20,7 +21,7 @@ type ( // RedirectPolicy to regulate the redirects in the resty client. // Objects implementing the RedirectPolicy interface can be registered as // - // Apply function should return nil to continue the redirect jounery, otherwise + // Apply function should return nil to continue the redirect journey, otherwise // return error to stop the redirect. RedirectPolicy interface { Apply(req *http.Request, via []*http.Request) error @@ -92,7 +93,7 @@ func getHostname(host string) (hostname string) { } // By default Golang will not redirect request headers -// after go throughing various discussion comments from thread +// after go throwing various discussion comments from thread // https://github.com/golang/go/issues/4800 // Resty will add all the headers during a redirect for the same host func checkHostAndAddHeaders(cur *http.Request, pre *http.Request) { diff --git a/request.go b/request.go index e72716fe..fec09763 100644 --- a/request.go +++ b/request.go @@ -489,7 +489,7 @@ func (r *Request) SetAuthToken(token string) *Request { // // client.R().SetAuthScheme("OAuth") // -// This auth header scheme gets added to all the request rasied from this client instance. +// This auth header scheme gets added to all the request raised from this client instance. // Also it can be overridden or set one at the request level is supported. // // Information about Auth schemes can be found in RFC7235 which is linked to below along with the page containing @@ -641,6 +641,8 @@ func (r *Request) SetPathParams(params map[string]string) *Request { // // Also you can override Path Params value, which was set at client instance // level. +// +// Since v2.8.0 func (r *Request) SetRawPathParam(param, value string) *Request { r.RawPathParams[param] = value return r @@ -664,6 +666,8 @@ func (r *Request) SetRawPathParam(param, value string) *Request { // // Also you can override Path Params value, which was set at client instance // level. +// +// Since v2.8.0 func (r *Request) SetRawPathParams(params map[string]string) *Request { for p, v := range params { r.SetRawPathParam(p, v) diff --git a/request_test.go b/request_test.go index 980928aa..a385097c 100644 --- a/request_test.go +++ b/request_test.go @@ -1317,7 +1317,7 @@ func TestDetectContentTypeForPointer(t *testing.T) { } type ExampleUser struct { - FirstName string `json:"frist_name"` + FirstName string `json:"first_name"` LastName string `json:"last_name"` ZipCode string `json:"zip_code"` } diff --git a/resty.go b/resty.go index 930a909c..5bbb842f 100644 --- a/resty.go +++ b/resty.go @@ -14,7 +14,7 @@ import ( ) // Version # of resty -const Version = "2.7.0" +const Version = "2.8.0" // New method creates a new Resty client. func New() *Client {