Merge pull request #48 from logpacker/refactor/err-handling-if-one-line

Make one-line if err != nil conditions
This commit is contained in:
Alex Pliutau 2017-11-23 09:20:10 +07:00 committed by GitHub
commit e6df3b7cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 72 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"net/http"
"strconv"
)
// GetAuthorization returns an authorization by ID
@ -17,8 +18,7 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err != nil {
if err = c.SendWithAuth(req, auth); err != nil {
return auth, err
}
@ -29,10 +29,8 @@ func (c *Client) GetAuthorization(authID string) (*Authorization, error) {
// To use this method, the original payment must have Intent set to "authorize"
// Endpoint: POST /v1/payments/authorization/ID/capture
func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture bool) (*Capture, error) {
isFinalStr := "false"
if isFinalCapture {
isFinalStr = "true"
}
isFinalStr := strconv.FormatBool(isFinalCapture)
buf := bytes.NewBuffer([]byte("{\"amount\":{\"currency\":\"" + a.Currency + "\",\"total\":\"" + a.Total + "\"},\"is_final_capture\":" + isFinalStr + "}"))
req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/authorization/"+authID+"/capture"), buf)
if err != nil {
@ -41,8 +39,7 @@ func (c *Client) CaptureAuthorization(authID string, a *Amount, isFinalCapture b
capture := &Capture{}
err = c.SendWithAuth(req, capture)
if err != nil {
if err = c.SendWithAuth(req, capture); err != nil {
return capture, err
}
@ -60,8 +57,7 @@ func (c *Client) VoidAuthorization(authID string) (*Authorization, error) {
auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err != nil {
if err = c.SendWithAuth(req, auth); err != nil {
return auth, err
}
@ -80,8 +76,7 @@ func (c *Client) ReauthorizeAuthorization(authID string, a *Amount) (*Authorizat
auth := &Authorization{}
err = c.SendWithAuth(req, auth)
if err != nil {
if err = c.SendWithAuth(req, auth); err != nil {
return auth, err
}

View File

@ -85,8 +85,8 @@ func (c *Client) ExecuteApprovedAgreement(token string) (*ExecuteAgreementRespon
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
e := ExecuteAgreementResponse{}
err = c.SendWithAuth(req, &e)
if err != nil {
if err = c.SendWithAuth(req, &e); err != nil {
return &e, err
}

View File

@ -24,8 +24,7 @@ func (c *Client) GrantNewAccessTokenFromAuthCode(code string, redirectURI string
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
err = c.SendWithBasicAuth(req, token)
if err != nil {
if err = c.SendWithBasicAuth(req, token); err != nil {
return token, err
}
@ -47,8 +46,7 @@ func (c *Client) GrantNewAccessTokenFromRefreshToken(refreshToken string) (*Toke
return token, err
}
err = c.SendWithAuth(req, token)
if err != nil {
if err = c.SendWithAuth(req, token); err != nil {
return token, err
}
@ -66,8 +64,7 @@ func (c *Client) GetUserInfo(schema string) (*UserInfo, error) {
return &u, err
}
err = c.SendWithAuth(req, &u)
if err != nil {
if err = c.SendWithAuth(req, &u); err != nil {
return &u, err
}

View File

@ -12,8 +12,7 @@ func (c *Client) GetOrder(orderID string) (*Order, error) {
return order, err
}
err = c.SendWithAuth(req, order)
if err != nil {
if err = c.SendWithAuth(req, order); err != nil {
return order, err
}
@ -34,8 +33,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization,
return auth, err
}
err = c.SendWithAuth(req, auth)
if err != nil {
if err = c.SendWithAuth(req, auth); err != nil {
return auth, err
}
@ -58,8 +56,7 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo
return capture, err
}
err = c.SendWithAuth(req, capture)
if err != nil {
if err = c.SendWithAuth(req, capture); err != nil {
return capture, err
}
@ -77,8 +74,7 @@ func (c *Client) VoidOrder(orderID string) (*Order, error) {
return order, err
}
err = c.SendWithAuth(req, order)
if err != nil {
if err = c.SendWithAuth(req, order); err != nil {
return order, err
}

View File

@ -35,8 +35,8 @@ func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string, ca
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
p := PaymentResponse{}
err = c.SendWithAuth(req, &p)
if err != nil {
if err = c.SendWithAuth(req, &p); err != nil {
return &p, err
}
@ -58,8 +58,7 @@ func (c *Client) CreatePayment(p Payment) (*CreatePaymentResp, error) {
response := &CreatePaymentResp{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
@ -79,8 +78,8 @@ func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*Exec
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
e := ExecuteResponse{}
err = c.SendWithAuth(req, &e)
if err != nil {
if err = c.SendWithAuth(req, &e); err != nil {
return &e, err
}
@ -101,8 +100,7 @@ func (c *Client) GetPayment(paymentID string) (*Payment, error) {
return &p, err
}
err = c.SendWithAuth(req, &p)
if err != nil {
if err = c.SendWithAuth(req, &p); err != nil {
return &p, err
}
@ -123,8 +121,7 @@ func (c *Client) GetPayments() ([]Payment, error) {
return p.Payments, err
}
err = c.SendWithAuth(req, &p)
if err != nil {
if err = c.SendWithAuth(req, &p); err != nil {
return p.Payments, err
}

View File

@ -15,8 +15,7 @@ func (c *Client) CreateSinglePayout(p Payout) (*PayoutResponse, error) {
response := &PayoutResponse{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
@ -35,8 +34,7 @@ func (c *Client) GetPayout(payoutBatchID string) (*PayoutResponse, error) {
response := &PayoutResponse{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
@ -55,8 +53,7 @@ func (c *Client) GetPayoutItem(payoutItemID string) (*PayoutItemResponse, error)
response := &PayoutItemResponse{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
@ -75,8 +72,7 @@ func (c *Client) CancelPayoutItem(payoutItemID string) (*PayoutItemResponse, err
response := &PayoutItemResponse{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}

View File

@ -14,8 +14,7 @@ func (c *Client) GetSale(saleID string) (*Sale, error) {
return sale, err
}
err = c.SendWithAuth(req, sale)
if err != nil {
if err = c.SendWithAuth(req, sale); err != nil {
return sale, err
}
@ -37,8 +36,7 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
return refund, err
}
err = c.SendWithAuth(req, refund)
if err != nil {
if err = c.SendWithAuth(req, refund); err != nil {
return refund, err
}
@ -56,8 +54,7 @@ func (c *Client) GetRefund(refundID string) (*Refund, error) {
return refund, err
}
err = c.SendWithAuth(req, refund)
if err != nil {
if err = c.SendWithAuth(req, refund); err != nil {
return refund, err
}

View File

@ -13,8 +13,8 @@ func (c *Client) StoreCreditCard(cc CreditCard) (*CreditCard, error) {
}
response := CreditCard{}
err = c.SendWithAuth(req, &response)
if err != nil {
if err = c.SendWithAuth(req, &response); err != nil {
return nil, err
}
@ -29,8 +29,7 @@ func (c *Client) DeleteCreditCard(id string) error {
return err
}
err = c.SendWithAuth(req, nil)
if err != nil {
if err = c.SendWithAuth(req, nil); err != nil {
return err
}
@ -46,8 +45,8 @@ func (c *Client) GetCreditCard(id string) (*CreditCard, error) {
}
response := CreditCard{}
err = c.SendWithAuth(req, &response)
if err != nil {
if err = c.SendWithAuth(req, &response); err != nil {
return nil, err
}
@ -72,8 +71,8 @@ func (c *Client) GetCreditCards(ccf *CreditCardsFilter) (*CreditCards, error) {
}
response := CreditCards{}
err = c.SendWithAuth(req, &response)
if err != nil {
if err = c.SendWithAuth(req, &response); err != nil {
return nil, err
}
@ -89,8 +88,8 @@ func (c *Client) PatchCreditCard(id string, ccf []CreditCardField) (*CreditCard,
}
response := CreditCard{}
err = c.SendWithAuth(req, &response)
if err != nil {
if err = c.SendWithAuth(req, &response); err != nil {
return nil, err
}

View File

@ -19,8 +19,7 @@ func (c *Client) CreateWebProfile(wp WebProfile) (*WebProfile, error) {
response := &WebProfile{}
err = c.SendWithAuth(req, response)
if err != nil {
if err = c.SendWithAuth(req, response); err != nil {
return response, err
}
@ -40,8 +39,7 @@ func (c *Client) GetWebProfile(profileID string) (*WebProfile, error) {
return &wp, err
}
err = c.SendWithAuth(req, &wp)
if err != nil {
if err = c.SendWithAuth(req, &wp); err != nil {
return &wp, err
}
@ -65,8 +63,7 @@ func (c *Client) GetWebProfiles() ([]WebProfile, error) {
return wps, err
}
err = c.SendWithAuth(req, &wps)
if err != nil {
if err = c.SendWithAuth(req, &wps); err != nil {
return wps, err
}
@ -90,8 +87,7 @@ func (c *Client) SetWebProfile(wp WebProfile) error {
return err
}
err = c.SendWithAuth(req, nil)
if err != nil {
if err = c.SendWithAuth(req, nil); err != nil {
return err
}
@ -111,8 +107,7 @@ func (c *Client) DeleteWebProfile(profileID string) error {
return err
}
err = c.SendWithAuth(req, nil)
if err != nil {
if err = c.SendWithAuth(req, nil); err != nil {
return err
}