From af8120920e8a5acec5f43467f14d152247c22142 Mon Sep 17 00:00:00 2001 From: Alex Pliutau Date: Wed, 29 Aug 2018 14:52:31 +0700 Subject: [PATCH] Simplify return values --- .travis.yml | 2 +- authorization.go | 32 ++++++++------------------------ client.go | 28 +++++++++++----------------- 3 files changed, 20 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4e758bf..edf5b53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,4 @@ go: install: - export PATH=$PATH:$HOME/gopath/bin script: - - go test + - go test -v -race diff --git a/authorization.go b/authorization.go index 344bae5..361f6a0 100644 --- a/authorization.go +++ b/authorization.go @@ -17,12 +17,8 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) { } auth := &Authorization{} - - if err = c.SendWithAuth(req, auth); err != nil { - return auth, err - } - - return auth, nil + err = c.SendWithAuth(req, auth) + return auth, err } // CaptureAuthorization captures and process an existing authorization. @@ -38,12 +34,8 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b } capture := &Capture{} - - if err = c.SendWithAuth(req, capture); err != nil { - return capture, err - } - - return capture, nil + err = c.SendWithAuth(req, capture) + return capture, err } // VoidAuthorization voids a previously authorized payment @@ -56,12 +48,8 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) { } auth := &Authorization{} - - if err = c.SendWithAuth(req, auth); err != nil { - return auth, err - } - - return auth, nil + err = c.SendWithAuth(req, auth) + return auth, err } // ReauthorizeAuthorization reauthorize a Paypal account payment. @@ -75,10 +63,6 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat } auth := &Authorization{} - - if err = c.SendWithAuth(req, auth); err != nil { - return auth, err - } - - return auth, nil + err = c.SendWithAuth(req, auth) + return auth, err } diff --git a/client.go b/client.go index db8bb5e..b494af8 100644 --- a/client.go +++ b/client.go @@ -52,26 +52,22 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) { } // SetHTTPClient sets *http.Client to current client -func (c *Client) SetHTTPClient(client *http.Client) error { +func (c *Client) SetHTTPClient(client *http.Client) { c.Client = client - return nil } // SetAccessToken sets saved token to current client -func (c *Client) SetAccessToken(token string) error { +func (c *Client) SetAccessToken(token string) { c.Token = &TokenResponse{ Token: token, } c.tokenExpiresAt = time.Time{} - - return nil } // SetLog will set/change the output destination. // If log file is set paypalsdk will log all requests and responses to this Writer -func (c *Client) SetLog(log io.Writer) error { +func (c *Client) SetLog(log io.Writer) { c.Log = log - return nil } // Send makes a request to the API, the response body will be @@ -112,18 +108,16 @@ func (c *Client) Send(req *http.Request, v interface{}) error { return errResp } - if v != nil { - if w, ok := v.(io.Writer); ok { - io.Copy(w, resp.Body) - } else { - err = json.NewDecoder(resp.Body).Decode(v) - if err != nil { - return err - } - } + if v == nil { + return nil } - return nil + if w, ok := v.(io.Writer); ok { + io.Copy(w, resp.Body) + return nil + } + + return json.NewDecoder(resp.Body).Decode(v) } // SendWithAuth makes a request to the API and apply OAuth2 header automatically.