Make routing deterministic.
JnBrymn opened this issue · comments
Right now routing involves iterating through a map to find a matching route. Since maps are not ordered, this can occasionally lead to unexpected matches. This also makes route testing more difficult.
Make routing deterministic! And make the routes ordered so that they match in the order specified by the user.
Probably the simplest way here is to replace the handlers map[*regexp.Regexp]contextHandler
with a routes []*regexp.Regexp
and handlers contextHandler
. Then iterate through the routes in order and upon a match retrieve the corresponding handler.
FYI, Go's ServeMux uses a map for matching routes too: http://golang.org/src/pkg/net/http/server.go#L1441
Yeah, but that one's kind of subpar IMO.
Something to look at: https://github.com/julienschmidt/httprouter
Working on this.