Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove github.com/pkg/errors in favor of Go core errors package #334

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cart/application/cartCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package application
import (
"context"
"encoding/gob"
"errors"
"fmt"
"strings"
"time"
Expand All @@ -11,7 +12,6 @@ import (
"flamingo.me/flamingo/v3/core/auth"
"flamingo.me/flamingo/v3/framework/flamingo"
"flamingo.me/flamingo/v3/framework/web"
"github.com/pkg/errors"
)

type (
Expand Down Expand Up @@ -74,7 +74,7 @@ func (ci *CartCacheIdentifier) CacheKey() string {
}

// BuildIdentifierFromCart creates a Cache Identifier from Cart Data
// DEPRICATED
// DEPRECATED
func BuildIdentifierFromCart(cart *cart.Cart) (*CartCacheIdentifier, error) {
if cart == nil {
return nil, errors.New("no cart")
Expand Down Expand Up @@ -158,7 +158,7 @@ func (cs *CartSessionCache) GetCart(ctx context.Context, session *web.Session, i

return nil, errors.New("cart cache contains invalid data at cache key")
}
cs.logger.WithContext(ctx).Debug("Did not Found cached cart %v", id.CacheKey())
cs.logger.WithContext(ctx).Debug("Did not find cached cart %v", id.CacheKey())

return nil, ErrNoCacheEntry
}
Expand All @@ -179,7 +179,7 @@ func (cs *CartSessionCache) CacheCart(ctx context.Context, session *web.Session,
}

// Invalidate a Cache Entry
func (cs *CartSessionCache) Invalidate(ctx context.Context, session *web.Session, id CartCacheIdentifier) error {
func (cs *CartSessionCache) Invalidate(_ context.Context, session *web.Session, id CartCacheIdentifier) error {
if cache, ok := session.Load(CartSessionCacheCacheKeyPrefix + id.CacheKey()); ok {
if cachedCartsEntry, ok := cache.(CachedCartEntry); ok {
cachedCartsEntry.IsInvalid = true
Expand All @@ -193,7 +193,7 @@ func (cs *CartSessionCache) Invalidate(ctx context.Context, session *web.Session
}

// Delete a Cache entry
func (cs *CartSessionCache) Delete(ctx context.Context, session *web.Session, id CartCacheIdentifier) error {
func (cs *CartSessionCache) Delete(_ context.Context, session *web.Session, id CartCacheIdentifier) error {
if _, ok := session.Load(CartSessionCacheCacheKeyPrefix + id.CacheKey()); ok {
session.Delete(CartSessionCacheCacheKeyPrefix + id.CacheKey())

Expand All @@ -205,7 +205,7 @@ func (cs *CartSessionCache) Delete(ctx context.Context, session *web.Session, id
}

// DeleteAll empties the Cache
func (cs *CartSessionCache) DeleteAll(ctx context.Context, session *web.Session) error {
func (cs *CartSessionCache) DeleteAll(_ context.Context, session *web.Session) error {
deleted := false
for _, k := range session.Keys() {
if stringKey, ok := k.(string); ok {
Expand Down
2 changes: 1 addition & 1 deletion cart/application/cartReceiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package application_test

import (
"context"
"errors"
"fmt"
"reflect"
"testing"
Expand All @@ -10,7 +11,6 @@ import (
authMock "flamingo.me/flamingo/v3/core/auth/mock"
"flamingo.me/flamingo/v3/framework/flamingo"
"flamingo.me/flamingo/v3/framework/web"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down
24 changes: 12 additions & 12 deletions cart/application/cartService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package application
import (
"context"
"encoding/gob"
"errors"
"fmt"

"flamingo.me/flamingo/v3/core/auth"
"github.com/pkg/errors"

"flamingo.me/flamingo/v3/framework/flamingo"
"flamingo.me/flamingo/v3/framework/web"
Expand Down Expand Up @@ -144,7 +144,7 @@ func (cs *CartService) ValidateCurrentCart(ctx context.Context, session *web.Ses
return cs.ValidateCart(ctx, session, decoratedCart), nil
}

// UpdatePaymentSelection updates the paymentselection in the cart
// UpdatePaymentSelection updates the payment selection in the cart
func (cs *CartService) UpdatePaymentSelection(ctx context.Context, session *web.Session, paymentSelection cartDomain.PaymentSelection) error {
cart, behaviour, err := cs.cartReceiverService.GetCart(ctx, session)
if err != nil {
Expand Down Expand Up @@ -424,7 +424,7 @@ func (cs *CartService) DeleteItem(ctx context.Context, session *web.Session, ite
cart, defers, err = behaviour.DeleteItem(ctx, cart, itemID, deliveryCode)
if err != nil {
cs.handleCartNotFound(session, err)
cs.logger.WithContext(ctx).WithField(flamingo.LogKeySubCategory, "DeleteItem").Error(errors.Wrap(err, "Trying to delete SKU :"+item.MarketplaceCode))
cs.logger.WithContext(ctx).WithField(flamingo.LogKeySubCategory, "DeleteItem").Error(fmt.Errorf("trying to delete SKU %q: %w", item.MarketplaceCode, err))

return err
}
Expand Down Expand Up @@ -772,7 +772,7 @@ func (cs *CartService) ApplyVoucher(ctx context.Context, session *web.Session, c
return cs.executeVoucherBehaviour(ctx, session, cart, couponCode, behaviour.ApplyVoucher)
}

// ApplyAny applies a voucher or giftcard to the cart
// ApplyAny applies a voucher or gift card to the cart
func (cs *CartService) ApplyAny(ctx context.Context, session *web.Session, anyCode string) (*cartDomain.Cart, error) {
cart, behaviour, err := cs.getCartAndBehaviour(ctx, session, "ApplyAny")
if err != nil {
Expand All @@ -793,7 +793,7 @@ func (cs *CartService) RemoveVoucher(ctx context.Context, session *web.Session,
return cs.executeVoucherBehaviour(ctx, session, cart, couponCode, behaviour.RemoveVoucher)
}

// ApplyGiftCard adds a giftcard to the cart
// ApplyGiftCard adds a gift card to the cart
func (cs *CartService) ApplyGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error) {
cart, behaviour, err := cs.getCartAndBehaviour(ctx, session, "ApplyGiftCard")
if err != nil {
Expand All @@ -805,7 +805,7 @@ func (cs *CartService) ApplyGiftCard(ctx context.Context, session *web.Session,
return nil, errors.New("ApplyGiftCard not supported")
}

// RemoveGiftCard removes a giftcard from the cart
// RemoveGiftCard removes a gift card from the cart
func (cs *CartService) RemoveGiftCard(ctx context.Context, session *web.Session, couponCode string) (*cartDomain.Cart, error) {
cart, behaviour, err := cs.getCartAndBehaviour(ctx, session, "RemoveGiftCard")
if err != nil {
Expand All @@ -829,7 +829,7 @@ func (cs *CartService) getCartAndBehaviour(ctx context.Context, session *web.Ses
}

// Executes provided behaviour regarding vouchers, this function serves to reduce duplicated code
// for voucher / giftcard behaviour as their internal logic is basically the same
// for voucher / gift card behaviour as their internal logic is basically the same
func (cs *CartService) executeVoucherBehaviour(ctx context.Context, session *web.Session, cart *cartDomain.Cart, couponCode string, fn promotionFunc) (*cartDomain.Cart, error) {
// cart cache must be updated - with the current value of cart
var defers cartDomain.DeferEvents
Expand Down Expand Up @@ -1033,16 +1033,16 @@ func (cs *CartService) CancelOrder(ctx context.Context, session *web.Session, or
return restoredCart, nil
}

func (cs *CartService) cancelOrder(ctx context.Context, session *web.Session, orderInfos placeorder.PlacedOrderInfos) error {
func (cs *CartService) cancelOrder(ctx context.Context, _ *web.Session, orderInfos placeorder.PlacedOrderInfos) error {
if cs.placeOrderService == nil {
return errors.New("No placeOrderService registered")
}

var cancelErr error

identitiy := cs.webIdentityService.Identify(ctx, web.RequestFromContext(ctx))
if identitiy != nil {
cancelErr = cs.placeOrderService.CancelCustomerOrder(ctx, orderInfos, identitiy)
identity := cs.webIdentityService.Identify(ctx, web.RequestFromContext(ctx))
if identity != nil {
cancelErr = cs.placeOrderService.CancelCustomerOrder(ctx, orderInfos, identity)
} else {
cancelErr = cs.placeOrderService.CancelGuestOrder(ctx, orderInfos)
}
Expand All @@ -1059,7 +1059,7 @@ func (cs *CartService) CancelOrderWithoutRestore(ctx context.Context, session *w
return cs.cancelOrder(ctx, session, orderInfos)
}

// GetDefaultDeliveryCode returns the configured default deliverycode
// GetDefaultDeliveryCode returns the configured default delivery code
func (cs *CartService) GetDefaultDeliveryCode() string {
return cs.defaultDeliveryCode
}
Expand Down
23 changes: 11 additions & 12 deletions cart/domain/cart/cart.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package cart
import (
"bytes"
"encoding/gob"
"errors"
"fmt"
"math/big"

"github.com/pkg/errors"

"flamingo.me/flamingo/v3/framework/web"

"flamingo.me/flamingo-commerce/v3/price/domain"
Expand Down Expand Up @@ -50,7 +49,7 @@ type (

DefaultCurrency string

// Additional non taxable totals
// Additional non-taxable totals
Totalitems []Totalitem

// AppliedGiftCards is a list of applied gift cards
Expand Down Expand Up @@ -255,7 +254,7 @@ func (c Cart) GetDeliveryByItemID(itemID string) (*Delivery, error) {
}
}

return nil, errors.Errorf("delivery not found for %q", itemID)
return nil, fmt.Errorf("delivery not found for %q", itemID)
}

// GetByItemID gets an item by its id
Expand All @@ -268,12 +267,12 @@ func (c Cart) GetByItemID(itemID string) (*Item, error) {
}
}

return nil, errors.Errorf("itemId %q in cart does not exist", itemID)
return nil, fmt.Errorf("itemId %q in cart does not exist", itemID)
}

// GetTotalQty for the product in the cart
func (c Cart) GetTotalQty(marketPlaceCode string, variantCode string) int {
qty := int(0)
qty := 0
for _, delivery := range c.Deliveries {
for _, currentItem := range delivery.Cartitems {
if currentItem.MarketplaceCode == marketPlaceCode && currentItem.VariantMarketPlaceCode == variantCode {
Expand All @@ -294,7 +293,7 @@ func (c Cart) GetByExternalReference(ref string) (*Item, error) {
}
}

return nil, errors.Errorf("uitemID %v in cart not existing", ref)
return nil, fmt.Errorf("cart item with ExternalReference %q not found", ref)
}

// ItemCount returns amount of cart items in the current cart
Expand Down Expand Up @@ -576,7 +575,7 @@ func (c Cart) GetCartTeaser() *Teaser {
}
}

// GetPaymentReference returns a string that can be used as reference to pass to payment gateway. You may want to use it. It returns either the reserved Order id or the cart id/entityid
// GetPaymentReference returns a string that can be used as reference to pass to payment gateway. You may want to use it. It returns either the reserved Order id or the cart id/entity id
func (c Cart) GetPaymentReference() string {
if c.AdditionalData.ReservedOrderID != "" {
return c.AdditionalData.ReservedOrderID
Expand Down Expand Up @@ -625,15 +624,15 @@ func (c Cart) GrandTotalCharges() domain.Charges {

// AddTax returns new Tax with this Tax added
func (t Taxes) AddTax(tax Tax) Taxes {
newTaxes := Taxes(t)
newTaxes := t
newTaxes = append(newTaxes, tax)

return newTaxes
}

// AddTaxWithMerge returns new Taxes with this Tax added
func (t Taxes) AddTaxWithMerge(taxToAddOrMerge Tax) Taxes {
newTaxes := Taxes(t)
newTaxes := t

for k, tax := range newTaxes {
if tax.Type == taxToAddOrMerge.Type {
Expand All @@ -654,7 +653,7 @@ func (t Taxes) AddTaxWithMerge(taxToAddOrMerge Tax) Taxes {

// AddTaxesWithMerge returns new Taxes with the given Taxes all added or merged in
func (t Taxes) AddTaxesWithMerge(taxes Taxes) Taxes {
newTaxes := Taxes(t)
newTaxes := t

for _, tax := range taxes {
newTaxes = newTaxes.AddTaxWithMerge(tax)
Expand Down Expand Up @@ -819,7 +818,7 @@ func (p PricedItems) Sum() domain.Price {
return sum
}

// TotalItems returns the Price per Totalitem - map key is total type
// TotalItems returns the Price per total item - map key is total type
func (p PricedItems) TotalItems() map[string]domain.Price {
return p.totalItems
}
Expand Down
3 changes: 1 addition & 2 deletions cart/domain/cart/cartServicePorts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ package cart
import (
"context"
"encoding/json"
"errors"

"flamingo.me/flamingo/v3/core/auth"
"flamingo.me/flamingo/v3/framework/flamingo"

"github.com/pkg/errors"
)

type (
Expand Down
Loading