ctx_interface.go — fiber Source File
Architecture documentation for ctx_interface.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 5970c75f_6b8c_d928_0978_508af8bdf1cc["ctx_interface.go"] 1cb0bb1d_c36d_d824_9fb1_7c83c35fd013["fasthttp"] 5970c75f_6b8c_d928_0978_508af8bdf1cc --> 1cb0bb1d_c36d_d824_9fb1_7c83c35fd013 style 5970c75f_6b8c_d928_0978_508af8bdf1cc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
// ⚡️ 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 (
"github.com/valyala/fasthttp"
)
// CustomCtx extends Ctx with the additional methods required by Fiber's
// internals and middleware helpers.
type CustomCtx interface {
Ctx
// Reset is a method to reset context fields by given request when to use server handlers.
Reset(fctx *fasthttp.RequestCtx)
// release is called before returning the context to the pool.
release()
// Abandon marks the context as abandoned. An abandoned context will not be
// returned to the pool when ReleaseCtx is called. This is used by the timeout
// middleware to return immediately while the handler goroutine continues.
// The cleanup goroutine must call ForceRelease when the handler finishes.
Abandon()
// IsAbandoned returns true if the context has been abandoned.
IsAbandoned() bool
// ForceRelease releases an abandoned context back to the pool.
// Must only be called after the handler goroutine has completely finished.
ForceRelease()
// Methods to use with next stack.
getMethodInt() int
getIndexRoute() int
getTreePathHash() int
getDetectionPath() string
getPathOriginal() string
getValues() *[maxParams]string
getMatched() bool
getSkipNonUseRoutes() bool
setIndexHandler(handler int)
setIndexRoute(route int)
setMatched(matched bool)
setSkipNonUseRoutes(skip bool)
setRoute(route *Route)
}
// NewDefaultCtx constructs the default context implementation bound to the
// provided application.
func NewDefaultCtx(app *App) *DefaultCtx {
// return ctx
ctx := &DefaultCtx{
// Set app reference
app: app,
}
ctx.DefaultReq.c = ctx
ctx.DefaultRes.c = ctx
return ctx
}
// AcquireCtx retrieves a new Ctx from the pool.
func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) CustomCtx {
ctx, ok := app.pool.Get().(CustomCtx)
if !ok {
panic(errCustomCtxTypeAssertion)
}
if app.hasCustomCtx {
if setter, ok := ctx.(interface{ setHandlerCtx(CustomCtx) }); ok {
setter.setHandlerCtx(ctx)
}
}
ctx.Reset(fctx)
return ctx
}
// ReleaseCtx releases the ctx back into the pool.
// If the context was abandoned (e.g., by timeout middleware), this is a no-op.
// Call ForceRelease only when you can guarantee no goroutines (including the
// requestHandler and ErrorHandler) still touch the context; the timeout
// middleware intentionally leaves abandoned contexts unreleased to avoid races.
func (app *App) ReleaseCtx(c CustomCtx) {
if c.IsAbandoned() {
return
}
c.release()
app.pool.Put(c)
}
Domain
Subdomains
Functions
Dependencies
- fasthttp
Source
Frequently Asked Questions
What does ctx_interface.go do?
ctx_interface.go is a source file in the fiber codebase, written in go. It belongs to the FiberCore domain, Context subdomain.
What functions are defined in ctx_interface.go?
ctx_interface.go defines 1 function(s): NewDefaultCtx.
What does ctx_interface.go depend on?
ctx_interface.go imports 1 module(s): fasthttp.
Where is ctx_interface.go in the architecture?
ctx_interface.go is located at ctx_interface.go (domain: FiberCore, subdomain: Context).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free