2020-02-08 01:05:13 +01:00
|
|
|
// 🚀 Fiber is an Express.js inspired web framework written in Go with 💖
|
2020-01-22 05:42:37 +01:00
|
|
|
// 📌 Please open an issue if you got suggestions or found a bug!
|
2020-02-08 01:05:13 +01:00
|
|
|
// 🖥 Links: https://github.com/gofiber/fiber, https://fiber.wiki
|
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-02-08 01:05:13 +01:00
|
|
|
// 💖 @valyala, @erikdubbelboer, @savsgio, @julienschmidt, @koddr
|
2020-01-15 03:07:49 +01:00
|
|
|
|
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-02-01 19:42:40 +03:00
|
|
|
// Ctx : struct
|
2020-01-11 04:59:51 +01:00
|
|
|
type Ctx struct {
|
2020-02-01 19:42:40 +03: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-02-01 19:42:40 +03:00
|
|
|
// Cookie : struct
|
2020-01-14 07:36:46 +01:00
|
|
|
type Cookie struct {
|
|
|
|
Expire int // time.Unix(1578981376, 0)
|
|
|
|
MaxAge int
|
|
|
|
Domain string
|
|
|
|
Path string
|
|
|
|
|
2020-02-01 19:42:40 +03:00
|
|
|
HTTPOnly bool
|
2020-01-14 07:36:46 +01:00
|
|
|
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
|
|
|
}
|