initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

13
core/rescue/recover.go Normal file
View File

@@ -0,0 +1,13 @@
package rescue
import "zero/core/logx"
func Recover(cleanups ...func()) {
for _, cleanup := range cleanups {
cleanup()
}
if p := recover(); p != nil {
logx.ErrorStack(p)
}
}

View File

@@ -0,0 +1,28 @@
package rescue
import (
"sync/atomic"
"testing"
"zero/core/logx"
"github.com/stretchr/testify/assert"
)
func init() {
logx.Disable()
}
func TestRescue(t *testing.T) {
var count int32
assert.NotPanics(t, func() {
defer Recover(func() {
atomic.AddInt32(&count, 2)
}, func() {
atomic.AddInt32(&count, 3)
})
panic("hello")
})
assert.Equal(t, int32(5), atomic.LoadInt32(&count))
}