4 ms·
One thing I don't like about default ServeMux is that addresses are prefixes. So `mux.HandleFunc("/"...)` always handles _everything_. And there is no easy wa
by shp0ngle 3y ago
One thing I don't like about default ServeMux is that addresses are prefixes.
So `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?
- mariusor 3y agoI would say that unless specified differently this bit of the documentation[1] still applies (second paragraph): > Longer patterns take precedence over shorter ones, https://pkg.go.dev/net/http#ServeMux https://pkg.go.dev/net/http#ServeMux
- jbamsterdam 3y agoNo, it does not. The length of the pattern isn't important anymore, only whether it overlaps with other patterns.
- mariusor 3y agoThat would be a breaking API change in my opinion. I bet you the length criterion will still apply for path patterns that don't include placeholders, even if not specifically mentioned in the proposal. [edit] Heh, I guess you'd know better. :D The comparison between the hn username and github username resolved favourably in the end. :P
- deleted 3y ago[deleted]
- FiloSottile 3y agoFrom the proposal: "There is one last, special wildcard: {$} matches only the end of the URL, allowing writing a pattern that ends in slash but does not match all extensions of that path. For example, the pattern /{$} matches the root page / but (unlike the pattern / today) does not match a request for /anythingelse."
- yankput 3y agoAhhh how did I miss that!! That is amazing. Goodbye gorilla mux.
- drdaeman 3y agoIdeally, this should be the default behavior, i.e. "/foo/" matching only "/foo/" and nothing else. And if one wants a prefix they should be able to explicitly spell it out like "/foo/{**}". But that’s not backwards-compatible, sadly, so this is going to remain a historical wart.