liveBook · Manning

Go get

As explained in Go in Practice, Second Edition

go get is a Go command that adds or retrieves package dependencies for a module.

go get adds or retrieves external package dependencies for a Go project. It accepts an individual package path or ./..., which scans the codebase for referenced external packages. section 1.2.4

Use go get for common dependency-management tasks:

  • Run go get PACKAGE_PATH to retrieve one package, such as golang.org/x/net/html. section 1.2.4
  • Run go get ./... to walk the codebase and retrieve referenced external packages. section 1.2.4
  • Run go get PACKAGE_PATH@VERSION to select a semantic-version tag rather than the latest version. section 6.1.3
  • Run go get -u to update all dependencies, or go get -u PACKAGE_PATH to update one; use go mod tidy afterward. section 6.1.3
  • Use go mod graph to inspect updated versions and transitive dependencies, and add -t when test packages matter. section 6.1.3

Adding an external package

Initialize the project with go mod init, import an external package such as golang.org/x/net/html, then run go get ./.... Go retrieves the package through its version-control system and makes it available to the workspace; the dependency is recorded in go.mod. section 1.2.4

$ go get ./...

Inspect the command form used to retrieve every external package referenced throughout a codebase. section 1.2.4

How Go in Practice, Second Edition covers it

How deep it goes
Explains package retrieval, version selection, updates, transitive dependencies, and cleanup, but not deployment configuration.
Examples
Uses golang.org/x/net/html, ./..., tagged versions, update commands, and go mod graph as concrete dependency-management examples.
What it assumes
Assumes a Go project with imports and typically begins after initializing a module with go mod init.
What you can do after
Operate/configure project dependencies, pin versions, update dependency graphs, and include packages needed for tests.
How it connects
Connects external packages with Go modules, go.mod, go mod tidy, semantic versioning, version-control systems, and transitive dependencies.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Go in Practice, Second Edition. The section links point to the parts of the book it draws on.