From 56d0060c35578558a16fdca38f732c7945fb5aa4 Mon Sep 17 00:00:00 2001 From: snail <9914016+snail-plus@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:25:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update=20base.go=20fix=20WithRecover=20?= =?UTF-8?q?=E6=97=A0=E6=B3=95recover=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- primitive/base.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/primitive/base.go b/primitive/base.go index a45fbb96..da6fb93e 100644 --- a/primitive/base.go +++ b/primitive/base.go @@ -85,12 +85,11 @@ func verifyIP(ip string) error { return nil } -var PanicHandler func(interface{}) +type PanicHandler func(interface{}) -func WithRecover(fn func()) { +func WithRecover(fn func(), handlers ...PanicHandler) { defer func() { - handler := PanicHandler - if handler != nil { + for _, handler := range handlers { if err := recover(); err != nil { handler(err) } From 3e3acdf1f9efe383d37f8988b8a8daf2b70bcb04 Mon Sep 17 00:00:00 2001 From: snail <9914016+snail-plus@users.noreply.github.com> Date: Tue, 4 Jul 2023 10:40:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix=20primitive=20WithRecover=20=E6=97=A0?= =?UTF-8?q?=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- primitive/base.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/primitive/base.go b/primitive/base.go index da6fb93e..d3ce4b27 100644 --- a/primitive/base.go +++ b/primitive/base.go @@ -89,8 +89,8 @@ type PanicHandler func(interface{}) func WithRecover(fn func(), handlers ...PanicHandler) { defer func() { - for _, handler := range handlers { - if err := recover(); err != nil { + if err := recover(); err != nil { + for _, handler := range handlers { handler(err) } }