Skip to content

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

Closed

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.

Activity

  1. changed the title [-]Panic in Fiber's Use method due to missing type conversion when using custom middleware[/-] [+]Panic in Fiber's Use method due to missing type conversion when using middleware[/+] on Feb 19, 2024
  2. changed the title [-]Panic in Fiber's Use method due to missing type conversion when using middleware[/-] [+]Panic in Fiber's server when registering handlers with middleware[/+] on Feb 19, 2024
  3. changed the title [-]Panic in Fiber's server when registering handlers with middleware[/-] [+]Panic in fiber's server when registering handlers with middleware[/+] on Feb 19, 2024
  4. added
    bug
    on Mar 25, 2024
  5. added this to the v2.2.0 milestone on Mar 25, 2024
  6. added a commit that references this issue on May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugserver:fiber

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions