News for hackers. Stuff that matters.
Re:Better HTTP server routing in Go 1.22 by eknkc on Monday October 16, 2023 @09:18AM (#37899474)
I believe it allows `/foo/bar` and `/foo/{id}` as the first one is more specific and has precedence. This looks fine to me.

Looks like it will panic in case you have `/foo/{id}/delete` and `/foo/bar/{action}`. /foo/bar/delete will match both, none is more specific so it panics. Feels reasonable. Having a first one wins precedence might be better though.

Re:Better HTTP server routing in Go 1.22 by karmakaze on Monday October 16, 2023 @09:56AM (#37899956)
I would expect and prefer the longer literal prefix to match. If the goal is to not have so many different routers in use, having some options like this case would be better than having one opinionated Go-way, which is how we end up with many libraries to fill common gaps.
Re:Better HTTP server routing in Go 1.22 by the_gipsy on Monday October 16, 2023 @11:24AM (#37901121)
The least surprising behavior would be matching `/boo/bar/{action}`, since we're dealing with path element separated by slashes, and the precedence case already exists otherwise.
Re:Better HTTP server routing in Go 1.22 by throwaway2990 on Monday October 16, 2023 @12:27PM (#37902223)
Na it’s dumb. Bar is very specific. It should be picked.
Re:Better HTTP server routing in Go 1.22 by troupo on Monday October 16, 2023 @12:56PM (#37902732)
It's a 404 Not Found or 500 Server Error.

HTTP server panicking is never reasonable

Re:Better HTTP server routing in Go 1.22 by avianlyric on Monday October 16, 2023 @02:12PM (#37903813)
The panic happens at handler registration i.e. binary startup, not while performing path matching. Having literally any tests in your application, literally anything that executes your binary before you ship it, will tell there's a problem. Your code simply won't be able start serving traffic if there's path routing ambiguity.

If you've managed to ship code that panicked during execution due to path routing ambiguity, then honestly your code is probably so riddled with bugs this is going to be the least of your issues.