Skip to content

Commit 393ae28

Browse files
committed
router: func
1 parent 91c5c12 commit 393ae28

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

router.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package godzilla
22

3-
import "sync"
3+
import (
4+
"sync"
5+
6+
"github.com/valyala/fasthttp"
7+
)
48

59
var (
610
defaultContentType = []byte("text/plain; charset=utf-8")
@@ -20,3 +24,20 @@ type matchResult struct {
2024
handlers handlersChain
2125
params map[string]string
2226
}
27+
28+
func (r *router) acquireCtx(fctx *fasthttp.RequestCtx) *context {
29+
ctx := r.pool.Get().(*context)
30+
31+
ctx.index = 0
32+
ctx.paramValues = make(map[string]string)
33+
ctx.requestCtx = fctx
34+
35+
return ctx
36+
}
37+
38+
func (r *router) releaseCtx(ctx *context) {
39+
ctx.handlers = nil
40+
ctx.paramValues = nil
41+
ctx.requestCtx = nil
42+
r.pool.Put(ctx)
43+
}

0 commit comments

Comments
 (0)