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
}
Chain is a structure for building a middleware chain and applying it to a final handler. Middleware is executed in the order they are added (the first added is the outermost).
func NewChain ¶
func NewChain(middlewares ...MiddlewareFunc) Chain
NewChain creates a new middleware chain. The middleware passed as arguments will form the initial chain.
func (Chain) HandlerFunc ¶
func (c Chain) HandlerFunc(final HandlerFunc) HandlerFunc
HandlerFunc applies the final HandlerFunc to the end of the middleware chain, and returns a HandlerFunc with all middleware applied. Middleware is executed in the order they were applied (the first added is the outermost). If the final handler is nil, it panics.
func (Chain) Then ¶
func (c Chain) Then(mw MiddlewareFunc) Chain
Then adds a new middleware to the end of the existing chain. This method returns a new Chain instance, and the original Chain is not modified.
type HandlerFunc ¶
type HandlerFunc func(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error)
HandlerFunc represents the type of AWS Lambda APIGatewayProxy event handler. This is the ultimate target function of the middleware chain.
func Use ¶
func Use(h HandlerFunc, middlewares ...MiddlewareFunc) HandlerFunc
Use is a helper function to apply multiple middleware to a single HandlerFunc. This is convenient when you want to apply middleware directly without using the Chain structure. Middleware is applied in reverse order of the arguments, so the execution order is the same as the argument order. Example: Use(h, m1, m2, m3) executes in the order m1 -> m2 -> m3 -> h -> m3 -> m2 -> m1
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
MiddlewareFunc represents the type of middleware that wraps a HandlerFunc and returns a new HandlerFunc. Middleware is used for request preprocessing, response postprocessing, or error handling.