Chapter 2. Module Recipes

2.0 Introduction

Managing dependencies is a crucial part of the software development lifecycle. A package manager is used to automate the downloading, updating, and removing of dependencies. This ultimately ensures that change management is done reliably and that nothing breaks after patches and upgrades.

You can find package managers everywhere. On Linux you have rpm, dpkg, apk, etc., and on macOS, you have Homebrew, MacPorts, Fink, etc. You can even consider the Mac App Store and the Windows Store package managers. Most programming languages also have package managers. For example, Python has pip and conda; Ruby has gems and bundler; PHP has PEAR, Composer, Poetry, and so on. Their features might differ, but at the end of the day, all package managers aim to make developers’ lives easier when managing libraries, especially third-party libraries.

Go has an interesting approach to package management. The go tool does package management; for example, go get will download and install third-party packages. However, before Go 1.11, Go didn’t bundle any versioning and dependency management mechanisms. This meant you inadvertently got only the latest version when you got a package.

Sure, there were third-party package and dependency managers like dep and Glide, but they weren’t part of Go. That changed in August 2018 when Go 1.11 introduced the concept of modules.

Of course, if your software program is small (you stuff everything into the main package) and ...

Get Go Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.