From c9eb8b7137a5cb7ca39059973db8a801692cffaa Mon Sep 17 00:00:00 2001 From: vvakame Date: Fri, 7 Jul 2017 18:57:02 +0900 Subject: [PATCH] Add SetHTTPClient function to *Client When we use GoogleAppEngine/Go environment, We should replace http.Client to urlfetch.Client. --- client.go | 11 +++++++++-- types.go | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index c9d38b2..324a7c7 100644 --- a/client.go +++ b/client.go @@ -19,7 +19,7 @@ func NewClient(clientID string, secret string, APIBase string) (*Client, error) } return &Client{ - client: &http.Client{}, + Client: &http.Client{}, ClientID: clientID, Secret: secret, APIBase: APIBase, @@ -50,6 +50,13 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) { return &t, err } +// SetHTTPClient sets *http.Client to current client +func (c *Client) SetHTTPClient(client *http.Client) error { + c.Client = client + return nil +} + + // SetAccessToken sets saved token to current client func (c *Client) SetAccessToken(token string) error { c.Token = &TokenResponse{ @@ -85,7 +92,7 @@ func (c *Client) Send(req *http.Request, v interface{}) error { req.Header.Set("Content-type", "application/json") } - resp, err = c.client.Do(req) + resp, err = c.Client.Do(req) c.log(req, resp) if err != nil { diff --git a/types.go b/types.go index 2f7cddc..4cfe166 100644 --- a/types.go +++ b/types.go @@ -107,7 +107,7 @@ type ( // Client represents a Paypal REST API Client Client struct { - client *http.Client + Client *http.Client ClientID string Secret string APIBase string