-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Fluent Method Chaining for Status and Type Methods Using Ge…
…nerics #3221
- Loading branch information
1 parent
8970f51
commit aac1b97
Showing
20 changed files
with
650 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️ | ||
// 🤖 Github Repository: https://github.com/gofiber/fiber | ||
// 📌 API Documentation: https://docs.gofiber.io | ||
|
||
package fiber | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/valyala/fasthttp" | ||
) | ||
|
||
type CustomCtx[T any] interface { | ||
Ctx[T] | ||
|
||
// Reset is a method to reset context fields by given request when to use server handlers. | ||
Reset(fctx *fasthttp.RequestCtx) | ||
|
||
// Methods to use with next stack. | ||
getMethodINT() int | ||
getIndexRoute() int | ||
getTreePath() string | ||
getDetectionPath() string | ||
getPathOriginal() string | ||
getValues() *[maxParams]string | ||
getMatched() bool | ||
setIndexHandler(handler int) | ||
setIndexRoute(route int) | ||
setMatched(matched bool) | ||
setRoute(route *Route) | ||
} | ||
|
||
func NewDefaultCtx(app *App[DefaultCtx]) *DefaultCtx { | ||
// return ctx | ||
return &DefaultCtx{ | ||
// Set app reference | ||
app: app, | ||
} | ||
} | ||
|
||
func (app *App[TCtx]) newCtx() Ctx[TCtx] { | ||
var c Ctx[TCtx] | ||
|
||
if app.newCtxFunc != nil { | ||
c = app.newCtxFunc(app) | ||
} else { | ||
c = NewDefaultCtx(app) | ||
} | ||
|
||
return c | ||
} | ||
|
||
// AcquireCtx retrieves a new Ctx from the pool. | ||
func (app *App[TCtx]) AcquireCtx(fctx *fasthttp.RequestCtx) Ctx[TCtx] { | ||
ctx, ok := app.pool.Get().(Ctx) | ||
|
||
if !ok { | ||
panic(errors.New("failed to type-assert to Ctx")) | ||
} | ||
ctx.Reset(fctx) | ||
|
||
return ctx | ||
} | ||
|
||
// ReleaseCtx releases the ctx back into the pool. | ||
func (app *App[TCtx]) ReleaseCtx(c Ctx[TCtx]) { | ||
c.release() | ||
app.pool.Put(c) | ||
} |
Oops, something went wrong.