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.
Hi,
When using the
RegisterHandlersWithOptionsfunction with middleware, a panic occurs with the message "use: invalid handler". This happens when the middleware, defined asMiddlewareFunc, is passed to Fiber'sUsemethod. TheUsemethod does not recognizeMiddlewareFuncas afiber.Handler, even thoughMiddlewareFuncis a type alias forfiber.Handler.This issue can be reproduced by trying to register middleware with a Fiber router using the
RegisterHandlersWithOptionsfunction.Potential Solution:
The issue seems to be due to the missing type conversion when passing the middleware function to the
Usemethod. To fix this, the template used to generate theRegisterHandlersWithOptionsfunction should be updated to include a type conversion for each middleware:This explicitly converts each
MiddlewareFuncto afiber.Handler, which should ensure it's recognized as such byUse. This change could be incorporated into theRegisterHandlersWithOptionsfunction to support middleware.