Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
func NewChain ¶
NewChain creates a new Chain instance with the base handler and initialized middlewares slice.
func (*Chain) Handler ¶
Handler returns the final handler with all middlewares and observers applied
func (*Chain) WithMiddleware ¶
WithMiddleware adds one or more middlewares to the chain. Middlewares execute in the order they are defined, from left to right. For example:
.WithMiddleware(mw1, mw2, mw3)
Will execute as: 1. mw1 (first middleware runs first) 2. mw2 3. mw3 4. Handler
This follows the same semantics as popular middleware chaining packages like Alice (github.com/justinas/alice) where the first middleware in the chain is the outermost handler that runs first. This matches the natural reading order of the code and makes it easier to reason about middleware execution.
func (*Chain) WithMiddlewareChain ¶
WithMiddlewareChain prepends a chain of middlewares (added in given order)
func (*Chain) WithObservers ¶
WithObservers adds handlers that run after the handler and middleware chain. Observers are typically used for logging, metrics collection, and other side effects. Note that observers will execute even if middleware returns early or stops processing. Observers should not write to the response as the main handler may have already sent headers. Use carefully as this could lead to unintended side effects when middleware fails.