Skip to content

Panic in fiber's server when registering handlers with middleware #1469

@emdfonseca

Description

@emdfonseca

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions