Simplify return values

This commit is contained in:
Alex Pliutau 2018-08-29 14:52:31 +07:00
parent af41710b9d
commit af8120920e
3 changed files with 20 additions and 42 deletions

View File

@ -9,4 +9,4 @@ go:
install:
- export PATH=$PATH:$HOME/gopath/bin
script:
- go test
- go test -v -race

View File

@ -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
}

View File

@ -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.