VividCortex / siesta

Composable framework for writing HTTP handlers in Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Working on this.

Done via #14.