-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
panic: wildcard route conflicts with existing children #205
Comments
Hello @carr123 , this is not a problem or issue from Gin, is from httprouter instead because how its made. I suggest the following: // ...
router.GET("/api/:user_id/requestedgroups", control.GetRequestedGroups)
// ...
if strings.HasPrefix(c.Request.RequestURI, "/api/test/basic_data_set_link") {
return control.GetBasicDataSetLink(c)
} else {
// your original "control.GetRequestedGroups" hanlder code ...
}
// ... |
Thanks @javierprovecho this is helpful (and thanks for this project it is great). I am wondering if httprouter is too simple for mainstream use, and if you guys plan to support other routers like https://github.com/dimfeld/httptreemux ? We have the same problem as carr123 and would prefer to avoid too many wrappers. Thanks. |
@wrunk +1 |
@wrunk no plans at the moment, everything of gin is around httprouter, and so speed and performance. Thank you for discovering me httptreeremux, I liked it!, I should compare speed against httprouter, and if it doesn't go so much slower, I think I will give it a try. Closing this issue. |
Is there any plans to support httptreeremux soon ? |
@javierprovecho @manucorporat #205 (comment) is really helpful for me, but how would you set different middleware for /:key (catch-all) and /admin? I think I've looked through all the relevant httprouter and gin issues |
I deleted those cursing comments, and hereby give out my solution, hopefully it would help people. After all, it's your own project. You didn't force us to use it. router.GET("/v1/images/:path1", GetHandler) // /v1/images/detail
router.GET("/v1/images/:path1/:path2", GetHandler) // /v1/images/<id>/history
func GetHandler(c *gin.Context) {
path1 := c.Param("path1")
path2 := c.Param("path2")
if path1 == "detail" && path2 == "" {
Detail(c)
} else if path1 != "" && path2 == "history" {
imageId := path1
History(c, imageId)
} else {
HandleHttpError(c, NewHttpError(404, "Page not found"))
}
} |
I need wildcard route at root, like |
This should not be closed, those solutions are not ideal. In my case, I have to use middleware in between, for example:
It would be very cumbersome to deal with this using solutions above. Edited:I made a workaround like this:
And in
However, I still find it ugly and not straight forward, hope Gin will implement someway else in future. |
This is great. I meet the similar problem:
The conflict panics. |
the above two lines conflict, and cause panic.
but it seems no problem. so, what's wrong with my code ??
thanks.
The text was updated successfully, but these errors were encountered: