From fd7f4d7b4e55668e36dc97c8a6510506728281e5 Mon Sep 17 00:00:00 2001 From: Webster Swift Date: Thu, 11 Sep 2025 16:02:25 +0300 Subject: [PATCH] Replace `github.com/pkg/errors` with Go's native `errors` and `fmt` package. --- drivers/store/redis/store.go | 10 +++++----- go.mod | 1 - rate.go | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/store/redis/store.go b/drivers/store/redis/store.go index 195b0d7..7fdcf25 100644 --- a/drivers/store/redis/store.go +++ b/drivers/store/redis/store.go @@ -2,14 +2,14 @@ package redis import ( "context" + "errors" + "fmt" "strings" "sync" "sync/atomic" "time" - "github.com/pkg/errors" libredis "github.com/redis/go-redis/v9" - "github.com/ulule/limiter/v3" "github.com/ulule/limiter/v3/drivers/store/common" ) @@ -178,12 +178,12 @@ func (store *Store) loadLuaScripts(ctx context.Context) error { luaIncrSHA, err := store.client.ScriptLoad(ctx, luaIncrScript).Result() if err != nil { - return errors.Wrap(err, `failed to load "incr" lua script`) + return fmt.Errorf(`failed to load "incr" lua script: %w`, err) } luaPeekSHA, err := store.client.ScriptLoad(ctx, luaPeekScript).Result() if err != nil { - return errors.Wrap(err, `failed to load "peek" lua script`) + return fmt.Errorf(`failed to load "peek" lua script: %w`, err) } store.luaIncrSHA = luaIncrSHA @@ -237,7 +237,7 @@ func isLuaScriptGone(err error) bool { func parseCountAndTTL(cmd *libredis.Cmd) (int64, int64, error) { result, err := cmd.Result() if err != nil { - return 0, 0, errors.Wrap(err, "an error has occurred with redis command") + return 0, 0, fmt.Errorf("an error has occurred with redis command: %w", err) } fields, ok := result.([]interface{}) diff --git a/go.mod b/go.mod index 8fadd2d..53dbc00 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.17 require ( github.com/gin-gonic/gin v1.9.1 - github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.6.2 github.com/stretchr/testify v1.8.4 github.com/valyala/fasthttp v1.50.0 diff --git a/rate.go b/rate.go index 46f656d..c367d6d 100644 --- a/rate.go +++ b/rate.go @@ -1,11 +1,10 @@ package limiter import ( + "fmt" "strconv" "strings" "time" - - "github.com/pkg/errors" ) // Rate is the rate. @@ -21,7 +20,7 @@ func NewRateFromFormatted(formatted string) (Rate, error) { values := strings.Split(formatted, "-") if len(values) != 2 { - return rate, errors.Errorf("incorrect format '%s'", formatted) + return rate, fmt.Errorf("incorrect format '%s'", formatted) } periods := map[string]time.Duration{ @@ -35,12 +34,12 @@ func NewRateFromFormatted(formatted string) (Rate, error) { p, ok := periods[period] if !ok { - return rate, errors.Errorf("incorrect period '%s'", period) + return rate, fmt.Errorf("incorrect period '%s'", period) } l, err := strconv.ParseInt(limit, 10, 64) if err != nil { - return rate, errors.Errorf("incorrect limit '%s'", limit) + return rate, fmt.Errorf("incorrect limit '%s'", limit) } rate = Rate{