Essential, production-ready Go packages

Go has an amazing standard library; building web servers and working with JSON doesn’t require any 3rd-party code — but for complex applications, you’ll find yourself exploring 3rd-party packages. Many newcomers to Go frequently ask me which packages I most commonly use outside of the standard library — so here is my list!

Dep will help you manage all of the packages you’re using — an appropriate first entry in my list :)

Don’t be put off by the words “official experiment” in its README. Dep is the best tool for your production-ready code right now. Modified BSD 3-Clause license.

Go Meta Linter helps you run a huge number of linters that exist for Go — 17 by default, with an additional 12 available — and normalises their output to a standard format.

I find it best to disable all linters by default, then explicitly enable the ones you want. You can create a `.gometalinter.json` file at the root of your project so contributors to your project can easily run the same configuration as CI. MIT license.

If you’re looking for an alternative to JSON, consider YAML or TOML.

For YAML: is based on a Go port of the well-known libyaml C library, supports most of YAML 1.1 and 1.2, and is developed by Canonical as part of the juju project. Apache 2.0 license.

For TOML: supports the latest TOML version 0.4.0, and is used by Dep. MIT license.

The standard library provides a generic interface around SQL databases, but you’ll need to choose a driver.

MySQL: is a native Go implementation and aims to support the 3 latest versions of Go (currently 1.7+). Mozilla Public 2.0 license.

Postgres: is a pure Go driver and is rock solid. MIT license.

You might also want to consider which extends the standard database/sql interfaces and adds concepts such as named parameter support in prepared statements, and the ability to marshal rows into structs/maps/slices. MIT license.

For some reason, logging is a highly contentious topics in terms of Go package selection. Go already has a great built-in log package. Personally I’m a huge fan of structured logging, and I’m going to list two packages you should consider for that:

Go kit — Log: is a minimal but powerful package for structured logging. It takes the less is more approach. MIT license.

Zap: is sold based on its impressive performance, but it also has a useful hooks system (e.g. to add Sentry integration). MIT license.

If you’re struggling to choose between these, I’d suggest go-kit/log.

If you’re coming from another programming language, you might be looking for a “framework” that can help you build-out web applications quickly, following best practices and using common conventions. Keep in mind “framework” might not be the right label for what you’re looking for in Go. is “a set of packages and best practices, which provide a comprehensive, robust, and trustable way of building microservices for organizations of any size”. I already linked to the log package above, but there’s a whole toolkit that you should check out if you’re building Microservices in Go. MIT license.

For simple URL routing the built-in http.ServeMux might suffice. However, many developers opt to use the Gorilla toolkit mux package. makes handling things like parsing parameters in URLs much easier. BSD 3-Clause license.

These are only a handful of awesome Go packages — there are many great packages out there, and the ecosystem is constantly evolving so I encourage you to continue evaluating the latest and greatest packages.

#DevOps, #Security, Go (#golang), #Linux, #Docker, #Kubernetes. DevOps Manager @Xero. Previously: DevTools Engineering Manager @Cloudflare. Opinions are my own.

#DevOps, #Security, Go (#golang), #Linux, #Docker, #Kubernetes. DevOps Manager @Xero. Previously: DevTools Engineering Manager @Cloudflare. Opinions are my own.