Skip to content

Commit

Permalink
chore: 更新依赖项
Browse files Browse the repository at this point in the history
  • Loading branch information
caixw committed Mar 16, 2024
1 parent 45bf444 commit 253bb02
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/issue9/mux/v7
require (
github.com/issue9/assert/v4 v4.1.1
github.com/issue9/errwrap v0.3.2
github.com/issue9/sliceutil v0.15.1
github.com/issue9/source v0.8.2
github.com/issue9/sliceutil v0.16.0
github.com/issue9/source v0.8.3
)

require golang.org/x/mod v0.16.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ github.com/issue9/assert/v4 v4.1.1 h1:OhPE8SB8n/qZCNGLQa+6MQtr/B3oON0JAVj68k8jJl
github.com/issue9/assert/v4 v4.1.1/go.mod h1:v7qDRXi7AsaZZNh8eAK2rkLJg5/clztqQGA1DRv9Lv4=
github.com/issue9/errwrap v0.3.2 h1:7KEme9Pfe75M+sIMcPCn/DV90wjnOcRbO4DXVAHj3Fw=
github.com/issue9/errwrap v0.3.2/go.mod h1:KcCLuUGiffjooLCUjL89r1cyO8/HT/VRcQrneO53N3A=
github.com/issue9/sliceutil v0.15.1 h1:mV1VlQSO5E8sh2ab6pypLg7TdgGZlDb30E8quli01xY=
github.com/issue9/sliceutil v0.15.1/go.mod h1:ldun6sT4/bOJxuMtOXhtc6P7GCwE7L+avV86HNks7qk=
github.com/issue9/source v0.8.2 h1:D8m8cZNvtp+cqkLVbMM/nUeO/5+e6KAhik6ogh/XX4g=
github.com/issue9/source v0.8.2/go.mod h1:PGSqeWtxDypSLMenKsq1Uehv/HCCyy3htkDS7rRCX6o=
github.com/issue9/sliceutil v0.16.0 h1:+gyumWF126mprQLiUi14s6SAeucMg1vuyPEh66VTtC8=
github.com/issue9/sliceutil v0.16.0/go.mod h1:ldun6sT4/bOJxuMtOXhtc6P7GCwE7L+avV86HNks7qk=
github.com/issue9/source v0.8.3 h1:MH883uljg0fupE/qkqJm3RqA5/l40KR+HsR7Mp3zjYY=
github.com/issue9/source v0.8.3/go.mod h1:H0Joo5go08sIMODLvQXpWwiWpGrH2MiTMFhKBZhVbH8=
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
20 changes: 13 additions & 7 deletions option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/issue9/assert/v4"
"github.com/issue9/assert/v4/rest"
Expand Down Expand Up @@ -53,6 +54,8 @@ func TestRecovery(t *testing.T) {

p := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { panic("panic test") })

// 未指定 Recovery

router := newRouter("")
a.NotNil(router).Nil(router.recoverFunc)
router.Get("/path", p)
Expand All @@ -68,13 +71,16 @@ func TestRecovery(t *testing.T) {
router = newRouter("", WriteRecovery(404, out))
a.NotNil(router).NotNil(router.recoverFunc)
router.Get("/path", p)
a.NotPanic(func() {
w := httptest.NewRecorder()
r := rest.Get(a, "/path").Request()

w := httptest.NewRecorder()
r := rest.Get(a, "/path").Request()
a.Go(func(a *assert.Assertion) {
router.ServeHTTP(w, r)
a.Contains(out.String(), "panic test").
Equal(w.Code, 404)
})
}).
Wait(time.Microsecond*500).
Contains(out.String(), "panic test", out.String()).
Contains(out.String(), "option_test.go:55", out.String()).
Equal(w.Code, 404)

// LogRecovery

Expand All @@ -91,7 +97,7 @@ func TestRecovery(t *testing.T) {
lines := strings.Split(out.String(), "\n")
a.Contains(lines[0], "panic test") // 保证第一行是 panic 输出的信息
a.Contains(lines[1], "TestRecovery.func1") // 保证第二行是 panic 函数名
a.True(strings.HasSuffix(lines[2], "option_test.go:54"), lines[2]) // 保证第三行是 panic 的行号
a.True(strings.HasSuffix(lines[2], "option_test.go:55"), lines[2]) // 保证第三行是 panic 的行号
})

// StatusRecovery
Expand Down
8 changes: 2 additions & 6 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import (
"sync"
)

// Context.Keys 的长度小于此值时才回收
const destroyMaxSize = 30

var contextPool = &sync.Pool{
New: func() any { return &Context{} },
}
var contextPool = &sync.Pool{New: func() any { return &Context{} }}

// Context 保存着路由匹配过程中的上下文关系
//
Expand Down Expand Up @@ -54,6 +49,7 @@ func (ctx *Context) Node() Node { return ctx.node }
func (ctx *Context) RouterName() string { return ctx.routerName }

func (ctx *Context) Destroy() {
const destroyMaxSize = 30
if ctx != nil && len(ctx.keys) <= destroyMaxSize {
contextPool.Put(ctx)
}
Expand Down

0 comments on commit 253bb02

Please sign in to comment.