1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-20 23:13:06 +00:00
fiber/pool.go
2020-01-03 05:57:41 -05:00

39 lines
576 B
Go

package fiber
import (
"sync"
"github.com/valyala/fasthttp"
)
// Context struct
type Ctx struct {
next bool
params *[]string
values []string
Fasthttp *fasthttp.RequestCtx
}
// Context pool
var ctxPool = sync.Pool{
New: func() interface{} {
return new(Ctx)
},
}
// Get new Context from pool
func acquireCtx(fctx *fasthttp.RequestCtx) *Ctx {
ctx := ctxPool.Get().(*Ctx)
ctx.Fasthttp = fctx
return ctx
}
// Return Context to pool
func releaseCtx(ctx *Ctx) {
ctx.next = false
ctx.params = nil
ctx.values = nil
ctx.Fasthttp = nil
ctxPool.Put(ctx)
}