-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Router not working with custom methods after parameter #2264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
At the moment Routes I would say this is working as intended - due to the limitations or design choices how parameters work. |
@aldas thanks! It makes sense, I agree its working as intended, but at the moment, there is maybe a workaround that would make the router match work for these routes now? |
I think currently you need to resort to (maybe) creating POST route for path something like that: func otherAction(c echo.Context, id int64) error {
return c.JSON(http.StatusOK, map[string]int64{"id": id})
}
func main() {
e := echo.New()
e.GET("/api/users/:idverb", func(c echo.Context) error {
idStr, verb, ok := strings.Cut(c.Param("idverb"), ":")
if !ok {
return echo.NewHTTPError(http.StatusBadRequest, "missing verb")
}
id, err := strconv.ParseInt(idStr, 10, 64)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "invalid id value")
}
switch verb {
case "otherAction":
return otherAction(c, id)
default:
return echo.NewHTTPError(http.StatusBadRequest, "invalid verb value")
}
})
if err := e.Start(":8080"); err != http.ErrServerClosed {
e.Logger.Fatal(err)
}
} this is not that eloquent but should work. |
Thanks again @aldas, but actually I have one permission service, where with base on the specific request, I need to find the generic route to check if the user has permission to access the endpoint. So this workarround wont work for me. I changed to mux that works as expected with custom methods |
Issue Description
Router Find not working with "custom methods".
It seems that the fix made in issue #2046, does not deal with routes that have a custom method after parameter, (examples in the code below)
Checklist
Expected behaviour
Match routes with custom actions and parameters
Actual behaviour
Overwriting routes, when it should treat as a different route
Steps to reproduce
Code bellow
Working code to debug
Version/commit
v4.9.0
The text was updated successfully, but these errors were encountered: