-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Hi,
When using the RegisterHandlersWithOptions function with middleware, a panic occurs with the message "use: invalid handler". This happens when the middleware, defined as MiddlewareFunc, is passed to Fiber's Use method. The Use method does not recognize MiddlewareFunc as a fiber.Handler, even though MiddlewareFunc is a type alias for fiber.Handler.
This issue can be reproduced by trying to register middleware with a Fiber router using the RegisterHandlersWithOptions function.
Potential Solution:
The issue seems to be due to the missing type conversion when passing the middleware function to the Use method. To fix this, the template used to generate the RegisterHandlersWithOptions function should be updated to include a type conversion for each middleware:
for _, m := range options.Middlewares {
router.Use(fiber.Handler(m))
}This explicitly converts each MiddlewareFunc to a fiber.Handler, which should ensure it's recognized as such by Use. This change could be incorporated into the RegisterHandlersWithOptions function to support middleware.