Essential, production-ready Go packages

Ryan Djurovich
3 min readMay 27, 2018

--

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!

Dependency Manager

Dep https://github.com/golang/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.

Linting Code

Go Meta Linter https://github.com/alecthomas/gometalinter 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.

YAML & TOML

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

For YAML: https://github.com/go-yaml/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: https://github.com/pelletier/go-toml supports the latest TOML version 0.4.0, and is used by Dep. MIT license.

SQL Databases

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

MySQL: https://github.com/go-sql-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: https://github.com/lib/pq is a pure Go driver and is rock solid. MIT license.

You might also want to consider https://github.com/jmoiron/sqlx 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.

Logging

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: https://github.com/go-kit/kit/tree/master/log is a minimal but powerful package for structured logging. It takes the less is more approach. MIT license.

Zap: https://github.com/uber-go/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.

Microservices “Framework”

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.

https://github.com/go-kit/kit 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.

HTTP Routing

For simple URL routing the built-in http.ServeMux might suffice. However, many developers opt to use the Gorilla toolkit mux package.

http://github.com/gorilla/mux 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.

--

--

Ryan Djurovich
Ryan Djurovich

Written by Ryan Djurovich

CEO & Founder @ Nadrama.com | Production-ready containers in your cloud account, in minutes. Built on Kubernetes & Open Source.

No responses yet