1. 35

  2. 5

    This is nice, now i want something similar for warp,actix-web,gotham,rocket,tide,nickel,thruster and axum. Bonus points for including hyper.

    1. 5

      I’ve really enjoyed using go-chi. My requirements are rather basic, just simple routing.

      1. 5

        Simple: use chi unless you have a really good reason not to.

        1. 4

          Nice article – it was interesting to me that gorilla/mux has “route reversal” (though I’ve never needed that personally). Note that chi also supports host routing: not the package itself, but with the go-chi/hostrouter middleware that’s part of the chi project (it works as stand-alone middleware too).

          For an in-depth look at building your own routing using regexp and other types of custom matching, see my article Different approaches to HTTP routing in Go. I also compare to Axel Wagner’s “ShiftPath” technique, and some of the popular router libraries (chi, gorilla, pat).

          1. 4

            Great article, but IMO http.ServeMux has a couple of other gotchas in addition to the ones mentioned, that make it more painful to use than it should be:

            1. No way to match “/foo” and “/foo/” with a single Handle() call - handler on “/foo/” will not match “/foo”, and vice versa.
            2. “/foo/” matches the entire sub-tree “/foo/…” - there is no way to match a single path component under a sub-tree.

            Yes, these can be worked around, but it’s usually just more straightforward to use a better router.

            1. 5

              it’s usually just more straightforward to use a better router.

              You can duplicate Handle calls to solve those problems. I dunno. Most of my projects these days have like zero to five dependencies? I think that’s something worth gunning for; if there’s a way to stay within the stdlib, even with a bit of toil, seems like it’s worth doing.

            2. 1

              These are all path/pattern-oriented routers. Are there any good resource-oriented routers in the style of Rails?

              1. 1

                NGL, this nerd snipped me into writing my own router.