From 83cd857c2743e83decdedcce195be001ae8f1333 Mon Sep 17 00:00:00 2001 From: zenghur Date: Sun, 26 Apr 2020 13:43:03 +0800 Subject: [PATCH] chore: remove error kit --- errorkit/error.go | 8 -------- redispattern/lockguard/lock_guard.go | 9 ++++----- 2 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 errorkit/error.go diff --git a/errorkit/error.go b/errorkit/error.go deleted file mode 100644 index d6c0d59..0000000 --- a/errorkit/error.go +++ /dev/null @@ -1,8 +0,0 @@ -package errorkit - -import "github.com/pkg/errors" - -// WithStack wrap an error with stack. -func WithStack(err error) error { - return errors.WithStack(err) -} diff --git a/redispattern/lockguard/lock_guard.go b/redispattern/lockguard/lock_guard.go index 13981b3..760461a 100644 --- a/redispattern/lockguard/lock_guard.go +++ b/redispattern/lockguard/lock_guard.go @@ -9,7 +9,6 @@ import ( "time" "github.com/xiaojiaoyu100/lizard/backoff" - "github.com/xiaojiaoyu100/lizard/errorkit" ) const ( @@ -40,7 +39,7 @@ func New(redis rediser, key string, setters ...Setter) (*LockGuard, error) { redis: redis, Key: key, Value: "", - retryTimes: 3, + retryTimes: 1, expiration: 30 * time.Second, } for _, setter := range setters { @@ -54,8 +53,8 @@ func New(redis rediser, key string, setters ...Setter) (*LockGuard, error) { // Run 锁住 func (guard *LockGuard) Run(ctx context.Context, handler Handler) error { - guard.reset() for i := 0; i < guard.lock.retryTimes; i++ { + guard.reset() guard.obtain() if !guard.lock.locked { if guard.lock.retryTimes > 1 { @@ -77,9 +76,9 @@ func (guard *LockGuard) Run(ctx context.Context, handler Handler) error { if r := recover(); r != nil { close(stop) if _, ok := r.(error); ok { - errChan <- errorkit.WithStack(r.(error)) + errChan <- fmt.Errorf("%w", r.(error)) } else { - errChan <- errorkit.WithStack(fmt.Errorf("%+v", r)) + errChan <- fmt.Errorf("%+v", r) } return }