@@ -15,6 +15,7 @@ import (
1515 "encoding/xml"
1616 "errors"
1717 "fmt"
18+ "github.com/hashicorp/go-retryablehttp"
1819 "io"
1920 "mime/multipart"
2021 "net/http"
@@ -68,9 +69,6 @@ type service struct {
6869// NewAPIClient creates a new API client. Requires a userAgent string describing your application.
6970// optionally a custom http.Client to allow for advanced features such as caching.
7071func NewAPIClient (cfg * Configuration ) * APIClient {
71- if cfg .HTTPClient == nil {
72- cfg .HTTPClient = http .DefaultClient
73- }
7472
7573 c := & APIClient {}
7674 c .cfg = cfg
@@ -164,7 +162,7 @@ func parameterToString(obj interface{}, collectionFormat string) string {
164162}
165163
166164// callAPI do the request.
167- func (c * APIClient ) callAPI (request * http .Request ) (* http.Response , error ) {
165+ func (c * APIClient ) callAPI (request * retryablehttp .Request ) (* http.Response , error ) {
168166 return c .cfg .HTTPClient .Do (request )
169167}
170168
@@ -182,7 +180,7 @@ func (c *APIClient) prepareRequest(
182180 queryParams url.Values ,
183181 formParams url.Values ,
184182 fileName string ,
185- fileBytes []byte ) (localVarRequest * http .Request , err error ) {
183+ fileBytes []byte ) (localVarRequest * retryablehttp .Request , err error ) {
186184
187185 var body * bytes.Buffer
188186
@@ -269,9 +267,9 @@ func (c *APIClient) prepareRequest(
269267
270268 // Generate a new request
271269 if body != nil {
272- localVarRequest , err = http .NewRequest (method , url .String (), body )
270+ localVarRequest , err = retryablehttp .NewRequest (method , url .String (), body )
273271 } else {
274- localVarRequest , err = http .NewRequest (method , url .String (), nil )
272+ localVarRequest , err = retryablehttp .NewRequest (method , url .String (), nil )
275273 }
276274 if err != nil {
277275 return nil , err
@@ -308,7 +306,7 @@ func (c *APIClient) prepareRequest(
308306 return nil , err
309307 }
310308
311- latestToken .SetAuthHeader (localVarRequest )
309+ latestToken .SetAuthHeader (localVarRequest . Request )
312310 }
313311
314312 // Basic HTTP Authentication
@@ -330,17 +328,17 @@ func (c *APIClient) prepareRequest(
330328}
331329
332330func (c * APIClient ) decode (v interface {}, b []byte , contentType string ) (err error ) {
333- if strings .Contains (contentType , "application/xml" ) {
334- if err = xml .Unmarshal (b , v ); err != nil {
335- return err
336- }
337- return nil
338- } else if strings .Contains (contentType , "application/json" ) {
339- if err = json .Unmarshal (b , v ); err != nil {
340- return err
341- }
342- return nil
331+ if strings .Contains (contentType , "application/xml" ) {
332+ if err = xml .Unmarshal (b , v ); err != nil {
333+ return err
343334 }
335+ return nil
336+ } else if strings .Contains (contentType , "application/json" ) {
337+ if err = json .Unmarshal (b , v ); err != nil {
338+ return err
339+ }
340+ return nil
341+ }
344342 return errors .New ("undefined response type" )
345343}
346344
0 commit comments