'losing Fiber contex.Params when using Fiber Adapter
I have an interceptor that receives http.Handler and returns http.Handler and I need to use it in my Fiber app.
When I use adaptor.FiberHandlerFunc to convert my Fiber handler to HTTP Handler and again use adaptor.HTTPHandler to convert HTTP Handler to Fiber handler and use it in my Fiber App, I lose contex.Params in my handler and I get invalid memory address or nil pointer dereference when calling for example ctx.Params("name")
route
root.Get("/user/:name", authMiddleware(interceptor, handler.SampleHandler, nil, nil), handler.SampleHandler)
func authMiddleware(interceptor *interceptor.CidaasInterceptor, resourceHandlerFunc fiber.Handler, scopes []string, roles []string) fiber.Handler {
options := options.EndpointOptions{
Scopes: scopes,
Roles: roles,
}
return adaptor.HTTPHandler(interceptor.VerifyTokenBySignature(adaptor.FiberHandlerFunc(resourceHandlerFunc), options))
}
Handler Function
func SampleHandler(ctx *fiber.Ctx) error {
name := ctx.Params("name") // I Got `invalid memory address or nil pointer dereference`
ctx.SendString(fmt.Sprintf("URI:%s,name:%s", ctx.Request().URI().String(), name))
return nil
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
