Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenny authored May 27, 2020
1 parent 840b1ac commit 2a7001a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func FiberHandler(h func(*fiber.Ctx)) http.Handler {

// FiberHandlerFunc wraps fiber handler to net/http handler func
func FiberHandlerFunc(h func(*fiber.Ctx)) http.HandlerFunc {
app := fiber.New()
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// New fasthttp request
var req fasthttp.Request
Expand Down Expand Up @@ -65,8 +66,7 @@ func FiberHandlerFunc(h func(*fiber.Ctx)) http.HandlerFunc {
var fctx fasthttp.RequestCtx
fctx.Init(&req, remoteAddr, nil)
// New fiber Ctx
ctx := fiber.AcquireCtx(&fctx)
defer fiber.ReleaseCtx(ctx)
ctx := app.AcquireCtx(&fctx)
// Execute fiber Ctx
h(ctx)

Expand All @@ -78,5 +78,6 @@ func FiberHandlerFunc(h func(*fiber.Ctx)) http.HandlerFunc {
w.Header().Add(sk, sv)
})
w.Write(ctx.Fasthttp.Response.Body())
app.ReleaseCtx(ctx)
})
}

0 comments on commit 2a7001a

Please sign in to comment.