gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
78.89k stars 8.02k forks source link

"wildcard route conflicts with existing children" #1681

Closed wodim closed 5 years ago

wodim commented 5 years ago
router.GET("/:something/", Blabla)
router.GET("/:something/else", Bleble)
router.GET("/:something/:different/:again", Blibli)

panic: wildcard route ':different' conflicts with existing children in path '/:something/:different/:again'

Am I doing something wrong or is this simply not allowed?

b3lc0d3 commented 5 years ago

https://github.com/gin-gonic/gin/issues/1301 , so it's not allowed

wodim commented 5 years ago

Wow, that is terrible.

thinkerou commented 5 years ago

expected, thanks! you should re-write your route.

wodim commented 5 years ago

Saying it's "expected" makes it double terrible, because it means you will never get around to fix it.

There is no way Gin should confuse Bleble with Blibli: Bleble has two slashes, and Blibli has three!

In the end I had to write my own router like this:

router.GET("/", ViewHome)
router.GET("/:first", ViewRouterOne)
router.GET("/:first/:second", ViewRouterTwo)
router.GET("/:first/:second/:third", ViewRouterThree)
router.GET("/:first/:second/:third/:fourth", ViewRouterFour)

Then from those functions you can redirect requests to the correct view functions. I hope this is useful to someone.

safwanolaimat commented 4 years ago

how this routes cause conflict

pGroup.POST("/fork", controllers.Fork)
pGroup.POST("/:id/process", controllers.processN)
marloncristian commented 4 years ago

Am I the only one who doesn't understand why something so basic is not implemented in gin?

wodim commented 4 years ago

https://github.com/gin-gonic/gin/issues/2016#issuecomment-523204888

LaysDragon commented 4 years ago

Am I the only one who doesn't understand why something so basic is not implemented in gin?

me either,such basic functional route supported by most http server in the world but not in gin therefore,I have to rewrite the old openapi spec to make path can work with gin

insomnius commented 4 years ago

How can i fix this? Where should i start to contribute to fix this?

LaysDragon commented 4 years ago

How can i fix this? Where should i start to contribute to fix this?

It's httprouter's problem that gin currently based on checkout this issue https://github.com/gin-gonic/gin/issues/2016

ridwanakf commented 3 years ago

is this limitation still persist now?

appcypher commented 3 years ago

Wow! Gin routing pattern matching is a mess. Now I have to refactor my app to use another framework.

shivamganwani commented 1 year ago

@appleboy

Member appleboy commented on Apr 8, 2021

bump to v1.7.0 version. See https://github.com/gin-gonic/gin/releases/tag/v1.7.0

Fix!!

appleboy commented 1 year ago

@shivamganwani Thank you for classifying.