Matt Silverlock

On Go's Web Application Ecosystem

Go just had its fourth birthday, and it’s finding a lot of popularity as a systems/operations language. Tools like Packer (from the creator of Vagrant) and Serf are great examples of how Go’s headline features (concurrency, ease-of-deployment) are well-suited to these use-cases.

But it’s also finding some life as a web programming language. A big part of this is owed to how great Go’s included net/http library is—particularly its extensibility. Go’s web application ecosystem also tends to focus on small, loosely coupled packages: tools that you can mix-and-match. Big, Rails-esque frameworks—understanding that Rails fills a major need for many!—aren’t typically favored: although this might change if an idiomatic, modular framework rears its head. Go’s web ecosystem might still be fairly green, but if you don’t mind getting your hands just a little dirty, there’s plenty of helpful packages out there:

  • Gorilla – it's hard to write a web application in Go without hearing about Gorilla. It's a collection of packages—a toolkit—that are independant of each other, but fill in some major use-cases. Routing, sessions, request context, forms-to-structs (and a few more): just use what you need/like and ignore what you don't. The components are regularly maintained/issues are responded to, and the packages themselves have concise API's.
  • Martini is a (very) new web framework for Go, but has managed to grab a solid fanbase already thanks to working with (and not against) Go's net/http interfaces. It's more like Sinatra or Flask than Rails, letting you bring your own DB layer, sessions, and templating.
  • nosurf – CSRF middleware that plugs into net/http: and therefore works with net/http, Gorilla and/or Martini.
  • Bones - a useful template for a web application, including some good design patterns
  • go.stripe is, well, a Go library for Stripe. It's relatively up-to-date, supports the major API features (Charges, Customers, Subscriptions, etc) and has good test coverage.
  • blackfriday provides safe Markdown processing, which is particularly useful when you're dealing with user input. The package is battle-tested too, having been around for over two years.
  • html/template is actually from Go's standard library. It's fairly minimalist, but as of Go 1.2 it picked up comparison operators. It's also extensible (via FuncMaps) and pretty fast. I've not found another templating library for Go that is regularly maintained or as tested as html/template

There’s also Revel. It’s a fairly big framework and has a bit of complexity to it. Many Gophers aren’t a fan of the way it does things, either. My opinion is that while it might speed up your first pass at an application, a lot of what it provides is tightly coupled (i.e. cookie based, unencrypted sessions!).

Given all this, frameworks (and ecosystems) like Flask, Sinatra, Django and Rails still have an advantage for when you want to get something done today: they’re very useful toolboxes, handle a lot of the boilerplate and have a lot of examples and packages to leverage. And, for many use-cases, performance will never be a problem.

Still, writing a web application in Go has been surprisingly easily. The amount of extra boilerplate I’ve needed to write (if you’re sans-framework like me) is fairly minimal (just shy of Sinatra), and you end up with something that’s extremely fast. Deployment is also easy, as there’s no need to worry about installing libraries, a runtime or checking/updating versions: deploy the binary, any supporting assets (i.e. templates, a config file) and front-end it with nginx.

There’s something to be said about being able to write a lean, mean web application and serve a ton of requests without huge hardware requirements, and I think Go will find a niche amongst developers and teams who want something a little more efficient than the norm.

Can’t get enough Go? Check out episode #3 from way back in 2009 with Rob Pike just after Go’s initial release. Check out episode #100 from recently with Rob Pike and Andrew Gerrand to learn what’s new in Go. You can also subscribe to our Go tag to keep up with all the Go freshens.


Sign in or Join to comment or subscribe

Player art
  0:00 / 0:00