Go Modules

Powerful Command-Line Applications in Go — by Ricardo Gerardi (8 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 About the Example Code | TOC | Online Resources 👉

The code examples in this book rely on Go modules, the standard method to control and manage package dependencies for Go applications. By using Go modules, you can write your Go programs outside of the legacy $GOPATH required by older versions of Go prior to 1.11. Modules also enable reproducible builds as they record the specific version of Go and the external packages required to reliably build the application. You can find more information about Go modules in the official Go blog posts, Using Go Modules[7] and New module changes in Go 1.16.[8] To follow the examples, you need Go 1.13 or greater with modules enabled.

Modules provide a standard way to group related packages into a single unit that can be versioned together. They enable consistent dependency management for your Go applications. To use modules, create a directory for your code and use the go mod init command to initialize a new module, along with a unique module identifier. Typically, the unique module identifier is based on the version control path used to store the code. Since the code examples in the book aren’t stored in a publicly accessible version control system, we’ll use pragprog.com/rggo as the prefix for all example modules in the book. To better implement the book’s examples, place your code in the $HOME/pragprog.com/rggo directory with sub-directories for each chapter. For example…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.