Documentation
¶
Overview ¶
Package interceptor wraps a handler on both sides: before it runs, after it returns, and around a failure.
A guard answers yes or no; an interceptor observes and may change what happens — timing, caching, retries, a response header, an audit record written only when the write succeeded.
Index ¶
- func Use(is ...Interceptor) fiber.Handler
- type Func
- type Interceptor
- func After(name string, fn func(c fiber.Ctx, handlerErr error)) Interceptor
- func Header(key, value string) Interceptor
- func Of(name string, wrap func(c fiber.Ctx, next fiber.Handler) error) Interceptor
- func OnSuccess(name string, fn func(c fiber.Ctx)) Interceptor
- func Timing(threshold time.Duration) Interceptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Use ¶
func Use(is ...Interceptor) fiber.Handler
Use composes interceptors into one fiber middleware. The first listed is the outermost: it sees the request first and the response last.
Types ¶
type Func ¶
Func adapts a plain function to Interceptor.
type Interceptor ¶
Interceptor wraps the rest of the chain.
An implementation MUST call next exactly once on the paths where it intends the handler to run, and must return next's error unless it is deliberately replacing the outcome. Swallowing that error turns a failed write into a 200.
func After ¶
func After(name string, fn func(c fiber.Ctx, handlerErr error)) Interceptor
After runs fn once the handler has returned, with the handler's error.
fn's own error is ignored on purpose: an audit write that fails must not turn a successful write into a 500 the client will retry.
func Header ¶
func Header(key, value string) Interceptor
Header sets a response header on the way out.
func OnSuccess ¶
func OnSuccess(name string, fn func(c fiber.Ctx)) Interceptor
OnSuccess runs fn only when the handler returned no error. This is where an audit record or an outbox row belongs.
func Timing ¶
func Timing(threshold time.Duration) Interceptor
Timing records how long the handler took and logs anything slower than threshold at warn.
It logs the slow ones only. A line per request is a metric wearing a log's clothing — it costs money to store and nobody reads it; a line for the 1% that were slow is read every time.