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: install:
- export PATH=$PATH:$HOME/gopath/bin - export PATH=$PATH:$HOME/gopath/bin
script: script:
- go test - go test -v -race

View File

@ -17,12 +17,8 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
} }
auth := &Authorization{} auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err = c.SendWithAuth(req, auth); err != nil { return auth, err
return auth, err
}
return auth, nil
} }
// CaptureAuthorization captures and process an existing authorization. // CaptureAuthorization captures and process an existing authorization.
@ -38,12 +34,8 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b
} }
capture := &Capture{} capture := &Capture{}
err = c.SendWithAuth(req, capture)
if err = c.SendWithAuth(req, capture); err != nil { return capture, err
return capture, err
}
return capture, nil
} }
// VoidAuthorization voids a previously authorized payment // VoidAuthorization voids a previously authorized payment
@ -56,12 +48,8 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
} }
auth := &Authorization{} auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err = c.SendWithAuth(req, auth); err != nil { return auth, err
return auth, err
}
return auth, nil
} }
// ReauthorizeAuthorization reauthorize a Paypal account payment. // ReauthorizeAuthorization reauthorize a Paypal account payment.
@ -75,10 +63,6 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat
} }
auth := &Authorization{} auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err = c.SendWithAuth(req, auth); err != nil { return auth, err
return auth, err
}
return auth, nil
} }

View File

@ -52,26 +52,22 @@ func (c *Client) GetAccessToken() (*TokenResponse, error) {
} }
// SetHTTPClient sets *http.Client to current client // 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 c.Client = client
return nil
} }
// SetAccessToken sets saved token to current client // SetAccessToken sets saved token to current client
func (c *Client) SetAccessToken(token string) error { func (c *Client) SetAccessToken(token string) {
c.Token = &TokenResponse{ c.Token = &TokenResponse{
Token: token, Token: token,
} }
c.tokenExpiresAt = time.Time{} c.tokenExpiresAt = time.Time{}
return nil
} }
// SetLog will set/change the output destination. // SetLog will set/change the output destination.
// If log file is set paypalsdk will log all requests and responses to this Writer // 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 c.Log = log
return nil
} }
// Send makes a request to the API, the response body will be // 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 return errResp
} }
if v != nil { if v == nil {
if w, ok := v.(io.Writer); ok { return nil
io.Copy(w, resp.Body)
} else {
err = json.NewDecoder(resp.Body).Decode(v)
if err != nil {
return err
}
}
} }
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. // SendWithAuth makes a request to the API and apply OAuth2 header automatically.