Re:Better HTTP server routing in Go 1.22
by lelanthran on Monday October 16, 2023 @11:44AM
(#37901469)
I understood what you were saying but it might be easier to read if you escaped the * characters.
Re:Better HTTP server routing in Go 1.22
by danpalmer on Monday October 16, 2023 @11:53AM
(#37901645)
Ha! Whoops! Thanks
Re:Better HTTP server routing in Go 1.22
by assbuttbuttass on Monday October 16, 2023 @11:46AM
(#37901515)
I'm pretty sure that example worked even before the recent changes. From the documentation:
> Longer patterns take precedence over shorter ones, so that if there are handlers registered for both "/images/" and "/images/thumbnails/", the latter handler will be called for paths beginning with "/images/thumbnails/" and the former will receive requests for any other paths in the "/images/" subtree.
Re:Better HTTP server routing in Go 1.22
by superb_dev on Monday October 16, 2023 @01:48PM
(#37903505)
The two routes `/foo/bar` and `/foo/*` are not ambiguous and would be allowed by the router
Re:Better HTTP server routing in Go 1.22
by danpalmer on Monday October 16, 2023 @03:58PM
(#37905571)
Are they? It seems that the latter matches the former. i.e. for the path `/foo/bar` there are 2 matching routes. One must take precedence, but this router doesn't appear to allow that.
This may just be a syntax thing, I was being loose with syntax, and meant that the `*` would match anything for the purposes of this example.
Re:Better HTTP server routing in Go 1.22
by pipe01 on Wednesday October 18, 2023 @02:22AM
(#37925394)
It does allow that, the one without wildcards is more specific so it'll pick that one
Re:Better HTTP server routing in Go 1.22
by greiskul on Monday October 16, 2023 @02:27PM
(#37904019)
This work, the panic is only triggered when the precedence rules can't fix a conflict.
The behaviour documented here is actually extremely sensible and is best practices for anyone calling themselves a software engineer. Fail as early as possible, with as clear a message as possible.
Re:Better HTTP server routing in Go 1.22
by the_gipsy on Monday October 16, 2023 @06:20PM
(#37907464)
But there is a precedence to pick for the panic case too.
Re:Better HTTP server routing in Go 1.22
by badrequest on Monday October 16, 2023 @03:06PM
(#37904618)
This pattern already works and would work with this change, you'd just need to define `/foo/bar` first.
You can of course always implement this within `/foo/`, but then you're implementing your own URL routing and working around the framework rather than working inside the framework.
This feels to me like it's a change designed for APIs, not a change designed for user-facing websites. For APIs URL structure is often well defined in a technical sense, and this sort of use-case is rare. For a user-facing site however there are UX concerns, marketing concerns, SEO concerns, all sorts of reasons why some lovely, technically correct REST-style URL structure just won't work in practice. Unfortunately I know this from experience.