Forcing a panic when 2 routes are matched seems counter intuitive to me (versus, idk, every other web framework which uses the first-to-be-registered route that matches). Are there go-specific reasons for that? The edge case of "you might register HTTP routes in a bunch of places and it's harder to find that if multiple routes match" seems like something that be worked around with tooling. I've (ab)used the behavior…
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.
Better HTTP server routing in Go 1.22
21–30 of 236 posts
Re: Better HTTP server routing in Go 1.22
#22But its nice that this functionality will be provided by Golang itself.
Re: Better HTTP server routing in Go 1.22
#23As I commented[1] I think the syntax is flawed in the proposal. You need to weirdly create a magic string to define your handler. Why not make it an actual argument, then using already existing constants is easier. [1] https://github.com/golang/go/issues/61410#issuecomment-16580...
Re: Better HTTP server routing in Go 1.22
#24The gorrila/mux project is weird and I am confused by it. Last year the maintainers archived the gorrila/mux project. Therefore i switched to another multiplexor called gin-gonic. Now as i saw the OP mentioning it in their blog, i went to take a look at the gorrila/mux project again to verify i correctly remembered the project to be archived. Apparently its not archived anymore, which brings the stability of the whol…
[0] https://gorilla.github.io/blog/2023-07-17-project-status-upd...
[1] https://www.reddit.com/r/golang/comments/1528e25/gorilla_web...
Re: Better HTTP server routing in Go 1.22
#25I don't like this. Is there a reason for using a stringified method prefix? I'd prefer the type safety of verb-specific methods (i.e. mux.Get, mux.Post etc) than magic strings validated at run time. Additionally editors can autocomplete/intellisense methods.
Not a fan either. I want to be sure that routing is going to work at compile time, not at runtime.
Re: Better HTTP server routing in Go 1.22
#26Will this finally end the eternal golang http router bikeshedding?
Re: Better HTTP server routing in Go 1.22
#27So `mux.HandleFunc("/"...)` always handles _everything_.
And there is no easy way to say "no, just handle exact matches, plus maybe ? queries". As gorilla/mux does.
I don't think that is changed in the new go?
Re: Better HTTP server routing in Go 1.22
#28Re: Better HTTP server routing in Go 1.22
#29Will this finally end the eternal golang http router bikeshedding?
lol no, will start the proliferation of more different abstractions over it
The primary utility of Go's net/http is that it is a "minimal framework" that provides a fairly common plug-level compatibility between various bits and pieces. The particular bits that it happens to provide by "default" are not really that consequential by comparison. I was actually surprised anyone touched the standard mux at all at this late date because there's so many other options already, and most of them just plug in with no fuss at all. All a router is is a handler that examines the request and then calls another handler as a result.