-
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
To everyone who's new here #2016
Comments
I wrote my own "router". Example: router.GET("/:first/:second/:third", ViewRouterThree) Then in ViewRouterThree you access func ViewRouterTwo(c *gin.Context) {
if c.Param("second") == "new" {
viewNewThreadForm(c)
return
} else if c.Param("first") == "recent" {
if c.Param("second") == "threads" {
viewRecentThreads(c)
return
} else if c.Param("second") == "posts" {
viewRecentPosts(c)
return
... Crappy but it works fine. Of course having a decent router would be nice. |
In my point, because Gin is based on httprouter (in pursuit of speed, a special algorithm is used.), there is no elegant solution that can maintain both speed and decent routing. |
this is idiomatic, imo
reduces parsing |
yes,I encounter problem of conflict between path and wildcard ,and need to rewrite the openapi spec...It is annoying while gin have some limit with restful api style url path. |
related issue: julienschmidt/httprouter#73 |
@appleboy Are there plans to support alternatives to |
yes, the conflicts issue is annoy my solutions are:
write like this:
change the route as:
the first noe is not bad, I did't find any good solution for the second one I hope there would be a support of alternatives |
Well, I have never thought a simple REST could cause problems like this. |
I would never have chosen Gin if I had known about this beforehand. Having to write my own router makes Gin worse than worthless. This needs to be configurable. |
I ended up here because I have a similar issue, which gave me the same error. I took a quick look at the code and it looks like Gin is creating a tree in memory with all routes. Because of that, there can't be overlap. A different approach that would solve both this issue and mine would be instead to keep all routes in a slice, and then iterate through them on each request. This way, the router would stop on the first match, and it would allow to have routes that partially overlap too. For example: router.GET("/:second/:id/:first/:thisshouldbethefirstinstead", handler)
router.GET("/:second/:id/:first", handler)
router.GET("/:second/:id", handler)
router.GET("/:second", handler) If you navigate to Now, I know that the current implementation, based on a tree, has a bit more performance, as it does less lookups on each route. In practice, however, this won't matter much: most apps have a small number of routes, and the difference in time should be negligible. Additionally, because requests are matched in order, developers could put the most common routes at the top, thus making very few lookups for most requests. There's significant prior art for doing routing this way:
|
I wrote a simple router based on this principle that has the same routing interface as the Gin engine (GET, POST, etc.). My router creates a generic, catch-all handler for each method, while adding the "actual" routes as regular expressions to a slice. When a request is received, Gin calls the generic catch-all handler, which in turn cycles through the slice of regexps to find the "real" handler. The generic handler also handles adding route parameters to the Gin Context, where they can be read just as if the Gin router had gone directly to the handler. It sucks to have to do this, but it does work. |
I would never use gin for this reason. |
This is a known issue and really need to be addressed, some kind of abstraction would be great. |
#1432 |
Guys please fix this! The library that has most stars should not have this kind of problems. My employers are considering firing me because of this bug, I really would appreciate you guys fixing this! |
totally sucks, never would like to use it |
Just hit the same problem everybody is having ... time to look to a different framework. |
Is there any intention to make something like this an opt-in configuration possibility if the 'raw speed' aspect of the original source of the issue is not to be resolved? |
Hi guys, any updates about this issue? |
Is this issue still persist now? just wondering. Still amazed that the most starred framework for its kind has this kinda problem. |
yes, the issue is still an issue.
…On Tue, 15 Dec 2020 at 07:00, Ridwan Afwan Karim Fauzi < ***@***.***> wrote:
Is this issue still persist now? just wondering. Still amazed that the
most starred framework for its kind has this kinda problem.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2016 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIDTGVHYCTHJZC7NLZD7AVLSU4CPFANCNFSM4IL5IANA>
.
--
[image: SWORD health] <https://swordhealth.com/>
Tiago Cardoso
Software Engineer | SWORD Health <https://swordhealth.com/>
+351 911 977 902 <+351912345678>
[image: Skype] [image: LinkedIn]
<https://pt.linkedin.com/in/tiagocardosoweb>
*Disclaimer:*
The sender of this message cannot ensure the security of its electronic
transmission and consequently does not accept liability for any fact which
may interfere with the integrity of its content.
|
Would love to see this issue resolved, but if it's not possible, or not on the roadmap it'd be a good idea to disclose this routing limitation prominently in the README. This format of nesting is standard in RESTful APIs and I will need to consider ripping Gin out of the repo because of this. |
Been tracking this issue for a while, and it seems like the problem is not just changing the router, is the performance impact that can happen after that. which seems irrelevant when you cannot comply with the standards. ripping out the lovely Gin is much harder than fixing this issue, but the pain of not having a standard router is convincing me to choose the harder approach. |
I would argue that the performance impact is irrelevant regardless. Micro-optimizations in the router is likely not what will make or break your app's performance overall. In the Node.Js space, Eran Hammer wrote this, which is definitely controversial but an interesting perspective: https://web.archive.org/web/20171017173141/https://medium.com/@eranhammer/when-500-faster-is-garbage-553121a088c3 |
Once gave up gin because of this problem, and later chose gin again, now I am considering giving up again. |
Hi Guys, please suggest for me other libraries, first time learning Golang, but I see have problem with the router, this thing is not good. |
Try echo |
Or Fiber. |
yes, this issue still persist |
@rustagram you still employed? |
Update: I haven't heard from @julienschmidt on that PR, but I ported it here as #2663 and it's 🟢 in CI. I'm not a maintainer here, and I hope the current ones welcome this functionality. 🤞 |
I discovered this issue right now, after porting 2k+ lines to gin. Can't say how lucky i am to see @rw-access PR seconds before considering moving out from this framework. Hope PR get merged. |
I would migrate to Echo. |
Finally. Is there a date for the next release? |
@matheus-meneses We will release the new version v1.7.0 this week |
@appleboy thanks |
bump to v1.7.0 version. See https://github.com/gin-gonic/gin/releases/tag/v1.7.0 |
yes:((( |
It's already solved |
|
To everyone who's new here:
If you use RESTful-Style API, router of gin will be a TROUBLEMAKER!
#205
#1681
#136
#2005
The root of the problem is httprouter
The text was updated successfully, but these errors were encountered: