For mux, is order of route registrations important?

493 views
Skip to first unread message

Enmanuel Rivera

unread,
Dec 11, 2012, 9:25:27 PM12/11/12
to goril...@googlegroups.com
I am trying to setup a router, and give it some routes to work with.

router.HandleFunc("/foo", globalFooFunc)
router.HandleFunc("/foo", queryFooFunc).Queries("bar", "")

I find that if I setup the routes in the order above, "globalFooFunc" is always invoked, irrelevant of wether my request URL has a bar parameter or not. If I register the second route first, then it works as I expected. Is order something I need to take into account when setting up routes? From reading the docs I got the impression, that t should work based on the depth of the URL, not the order routes where registered in the router.

Is this a bug? Am I just not interpreting this correctly?

Thanks.

Rodrigo Moraes

unread,
Dec 12, 2012, 3:54:32 AM12/12/12
to Gorilla web toolkit
On Dec 12, 12:25 am, Enmanuel Rivera wrote:
> Is this a bug? Am I just not interpreting this correctly?

Hi,
This works as intended. Order matters and the first one that matches
is used.

I considered a mechanism to use a more specific route first, but
concluded that the behavior becomes less predictable and thus less
intuitive. This was mostly based on my experience with
werkzeug.routing (Python), which has a priority rank but the result is
not always obvious. I'd love to hear other opinions.

-- rodrigo
Reply all
Reply to author
Forward
0 new messages