libFiber

package
v2.0.0-...-51e8ac7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package libFiber provides the v2 Fiber web framework adapter for requestCore.

It embeds the v1 github.com/hmmftg/requestCore/libFiber.FiberParser and adds raw response writing, cookie access, and v2 routing support.

Fiber uses fasthttp (not net/http), so the SendResponse method writes directly to the fiber.Ctx response rather than through http.ResponseWriter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFiberCtx

func GetFiberCtx(ctx any) *fiber.Ctx

GetFiberCtx extracts the fiber.Ctx from a LegacyContext created by FiberRouter. Since v2 now passes *fiber.Ctx directly as LegacyContext, this helper type-asserts it.

Types

type FiberParserV2

type FiberParserV2 struct {
	legacyLibFiber.FiberParser
	// contains filtered or unexported fields
}

FiberParserV2 extends the v1 FiberParser with raw response writing and cookie access for v2 renderer and session support.

func InitContextV2

func InitContextV2(c *fiber.Ctx) *FiberParserV2

InitContextV2 creates a FiberParserV2 from a Fiber context.

func (*FiberParserV2) GetCookie

func (p *FiberParserV2) GetCookie(name string) string

GetCookie returns the value of the named request cookie.

func (*FiberParserV2) SendResponse

func (p *FiberParserV2) SendResponse(status int, contentType string, body []byte) error

SendResponse writes a raw response with the given status, content type, and body bytes to the Fiber response. This bypasses net/http entirely and writes directly to the fasthttp response. If a CommitState is bound and already committed, returns nil without writing. Before writing, the before-commit hook runner is invoked (if set) so that session cookies and other pre-write side effects are persisted even for direct parser writes.

func (*FiberParserV2) SetBeforeCommitHookRunner

func (p *FiberParserV2) SetBeforeCommitHookRunner(fn func() error)

SetBeforeCommitHookRunner binds a function that runs before-commit hooks before SendResponse writes the response.

func (*FiberParserV2) SetCommitState

func (p *FiberParserV2) SetCommitState(cs *v2wf.CommitState)

SetCommitState binds the request's CommitState to this parser so that SendResponse can check and update the committed status.

func (*FiberParserV2) SetCookie

func (p *FiberParserV2) SetCookie(cookie *http.Cookie)

SetCookie sets an HTTP response cookie on the Fiber response. Fiber's cookie API differs from net/http, so we map all http.Cookie fields to Fiber's cookie methods, including SameSite.

type FiberRouter

type FiberRouter struct {
	// contains filtered or unexported fields
}

FiberRouter implements routing.Router and routing.RouteGroup for Fiber.

func NewRouter

func NewRouter(app *fiber.App) *FiberRouter

NewRouter creates a new FiberRouter from a Fiber app.

func NewRouterFromGroup

func NewRouterFromGroup(app *fiber.App, group fiber.Router) *FiberRouter

NewRouterFromGroup creates a new FiberRouter from an existing Fiber group.

func (*FiberRouter) Delete

func (r *FiberRouter) Delete(pattern string, handler routing.Handler) error

Delete registers a DELETE handler.

func (*FiberRouter) Get

func (r *FiberRouter) Get(pattern string, handler routing.Handler) error

Get registers a GET handler.

func (*FiberRouter) Group

func (r *FiberRouter) Group(prefix string) routing.RouteGroup

Group creates a sub-group with the given prefix.

func (*FiberRouter) Handle

func (r *FiberRouter) Handle(method, pattern string, handler routing.Handler) error

Handle registers a handler for the given method and pattern.

func (*FiberRouter) Head

func (r *FiberRouter) Head(pattern string, handler routing.Handler) error

Head registers a HEAD handler.

func (*FiberRouter) MethodNotAllowed

func (r *FiberRouter) MethodNotAllowed(handler routing.Handler)

MethodNotAllowed sets the handler for disallowed methods. The handler is dispatched by the catch-all registered by NotFound (or by this method if NotFound was not called).

func (*FiberRouter) Native

func (r *FiberRouter) Native() any

Native returns the underlying Fiber app.

func (*FiberRouter) NotFound

func (r *FiberRouter) NotFound(handler routing.Handler)

NotFound sets the handler for unmatched routes. It registers a single catch-all that dispatches either the 404 handler (no route matches the path) or the 405 handler (a route matches the path but with a different method), ensuring the two do not shadow each other.

func (*FiberRouter) Patch

func (r *FiberRouter) Patch(pattern string, handler routing.Handler) error

Patch registers a PATCH handler.

func (*FiberRouter) Post

func (r *FiberRouter) Post(pattern string, handler routing.Handler) error

Post registers a POST handler.

func (*FiberRouter) Put

func (r *FiberRouter) Put(pattern string, handler routing.Handler) error

Put registers a PUT handler.

func (*FiberRouter) SetErrorHandler

func (r *FiberRouter) SetErrorHandler(handler *response.Handler)

SetErrorHandler installs the v2 response handler and error registry used for centralized error dispatch.

func (*FiberRouter) With

func (r *FiberRouter) With(middleware ...routing.Middleware) routing.RouteGroup

With returns a new group with additional middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL