1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-25 00:04:07 +00:00
fiber/context.go

60 lines
1.1 KiB
Go
Raw Normal View History

2020-01-22 05:42:37 +01:00
// 🔌 Fiber is an Expressjs inspired web framework build on 🚀 Fasthttp.
// 📌 Please open an issue if you got suggestions or found a bug!
2020-01-16 06:02:00 +01:00
// 🖥 https://github.com/gofiber/fiber
2020-01-15 03:07:49 +01:00
2020-01-16 00:24:58 +01:00
// 🦸 Not all heroes wear capes, thank you to some amazing people
2020-01-15 03:07:49 +01:00
// 💖 @valyala, @dgrr, @erikdubbelboer, @savsgio, @julienschmidt
2019-12-30 07:29:42 -05:00
package fiber
import (
2020-01-11 04:59:51 +01:00
"sync"
2019-12-30 07:29:42 -05:00
"github.com/valyala/fasthttp"
)
2020-01-11 04:59:51 +01:00
// Ctx struct
type Ctx struct {
2020-01-15 03:07:49 +01:00
route *route
2020-01-11 04:59:51 +01:00
next bool
params *[]string
values []string
Fasthttp *fasthttp.RequestCtx
}
2020-01-09 03:33:09 +01:00
2020-01-14 07:36:46 +01:00
// Cookie :
type Cookie struct {
Expire int // time.Unix(1578981376, 0)
MaxAge int
Domain string
Path string
HttpOnly bool
Secure bool
SameSite string
}
2020-01-11 04:59:51 +01:00
// Ctx pool
2020-01-28 14:28:09 -05:00
var poolCtx = sync.Pool{
2020-01-11 04:59:51 +01:00
New: func() interface{} {
return new(Ctx)
},
}
// Get new Ctx from pool
func acquireCtx(fctx *fasthttp.RequestCtx) *Ctx {
2020-01-28 14:28:09 -05:00
ctx := poolCtx.Get().(*Ctx)
2020-01-11 04:59:51 +01:00
ctx.Fasthttp = fctx
return ctx
}
// Return Context to pool
func releaseCtx(ctx *Ctx) {
2020-01-15 03:07:49 +01:00
ctx.route = nil
2020-01-11 04:59:51 +01:00
ctx.next = false
2019-12-30 07:29:42 -05:00
ctx.params = nil
ctx.values = nil
2020-01-11 04:59:51 +01:00
ctx.Fasthttp = nil
2020-01-28 14:28:09 -05:00
poolCtx.Put(ctx)
2019-12-30 07:29:42 -05:00
}