Live data from Hacker News

Mux – A lightweight, fast HTTP request router for Go

github.com

11–20 of 80 posts

Re: Mux – A lightweight, fast HTTP request router for Go

#11
post #5

I don't usually say this but - isn't this a poor choice of name? Gorilla framework's Mux [0] has been around awhile and is quite popular for routing in Go. [0] https://github.com/gorilla/mux

I think they are both copying the stdlib terminology https://golang.org/pkg/net/http/#ServeMux

Historically gophers haven't minded the occasional namespace collision: https://github.com/golang/go/issues/9

Re: Mux – A lightweight, fast HTTP request router for Go

#12
post #3
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

These links are pretty cool. Are there any tutorials or walkthroughs you would recommend? Like, Go has always interested me but I have no idea where to start to get an experience like say ExpressJS or even where to find templating or rendering. Any suggestions are appreciated!

When I was learning Go, Negroni was where I left off and felt like what you may be looking for as a next step: https://github.com/urfave/negroni (I"m sure someone more experienced can provide more context or other / better links -- thought this would be a better answer than none until then)

Re: Mux – A lightweight, fast HTTP request router for Go

#13
post #5

I don't usually say this but - isn't this a poor choice of name? Gorilla framework's Mux [0] has been around awhile and is quite popular for routing in Go. [0] https://github.com/gorilla/mux

I typically read the HN comments before clicking on a link, and I actually thought this _was_ a post about gorilla/mux until I got to your comment.

Same here!

Re: Mux – A lightweight, fast HTTP request router for Go

#14
post #3
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

These links are pretty cool. Are there any tutorials or walkthroughs you would recommend? Like, Go has always interested me but I have no idea where to start to get an experience like say ExpressJS or even where to find templating or rendering. Any suggestions are appreciated!

With go there is really less emphasis on taking advantage of a web framework like expressjs (look at go alternatives like gin) and building server functionality from the std library (since everything you need is there). I wrote a small helper library to help with template rendering if you're interested in looking at the source to see how you can take advantage of the std library for templating: https://github.com/dannav/migo

Re: Mux – A lightweight, fast HTTP request router for Go

#15
My favourite current HTTP request router is https://github.com/pressly/chi

The list of those using it in production includes:

- Pressly

- Cloudflare

- Heroku

- 99designs

- Origami

- IT Jobs Watch

- CrowdRiff

At Cloudflare it's our default router for internal APIs, which are all written in Go.

(and yes it uses a trie)

Re: Mux – A lightweight, fast HTTP request router for Go

#16
post #15

My favourite current HTTP request router is https://github.com/pressly/chi The list of those using it in production includes: - Pressly - Cloudflare - Heroku - 99designs - Origami - IT Jobs Watch - CrowdRiff At Cloudflare it's our default router for internal APIs, which are all written in Go. (and yes it uses a trie)

Do you know how it stacks up to httprouter for example? We can run benchmarks all day but it would be cool if you happened to have some real production statistics, by any change?

Re: Mux – A lightweight, fast HTTP request router for Go

#17
What's the use case for all these routing libraries? Why not write a few lines of procedural code? It's a natural encoding of the routes "trie".

     @methods('POST')
     def set_int(request):
         x = pop_int_component(request)
         no_more_components(request)
         do_set_the_int(x)
         return Ok

     def myapp(request):
         x = pop_id_component(request)
         if x == 'set_int':
             return set_int(request)
         else:
             return NotFound
No type system hacks, extremely modular and simple to understand. Exceptions can replace basically all the boilerplate. The only drawback being there's no URL generation, but it's not like most sites have so many URLs that writing this by hand (directly in HTML templates or as "inverse functions") would be unmaintainable.

Re: Mux – A lightweight, fast HTTP request router for Go

#18

What's the use case for all these routing libraries? Why not write a few lines of procedural code? It's a natural encoding of the routes "trie". @methods('POST') def set_int(request): x = pop_int_component(request) no_more_components(request) do_set_the_int(x) return Ok def myapp(request): x = pop_id_component(request) if x == 'set_int': return set_int(request) else: return NotFound No type system hacks, extremely mo…

It's not a python router though, it's for go.

In this case, I don't see any typesystem hacks either, it uses the standard library types and as it looks, can just hook up to net/http/ServeFunc typed functions, which are basically what you'll use anyway if you use the standard library.

I don't quite understand what your irk is with this particular library (excepts that it's not the net/http default mux)

Re: Mux – A lightweight, fast HTTP request router for Go

#20
post #2

Does it use a trie? If not, it probably should. Here's a wonderful talk on using that datastructure (with go) for the gov uk url router: https://gdstechnology.blog.gov.uk/2013/12/05/building-a-new-... The Vulcan proxy from Mailgun does the same thing: http://vulcand.github.io/proxy.html#route It looks like it doesn't, so existing open source golang url routers will perform much better, contrary to this post. The one…

Looks like it uses regexp... There isn't any benchmark code as one would expect when making a claim that it's "fast".
Post reply on HN