Adding External Dependencies
go get, versioning, and the module cache
Finding Packages
The primary resource for finding Go packages is pkg.go.dev. Search for packages, read docs, and see usage examples:
# Search and explore at https://pkg.go.dev
# Popular packages:
# github.com/gin-gonic/gin — HTTP framework
# github.com/stretchr/testify — test assertions
# golang.org/x/sync — extended sync primitives
# github.com/spf13/cobra — CLI framework
# github.com/jackc/pgx/v5 — PostgreSQL drivergo get: Adding a Dependency
Use go get to add a dependency. It downloads the module and updates go.mod and go.sum:
# Add latest version
go get github.com/stretchr/testify
# Add specific version
go get github.com/stretchr/testify@v1.8.4
# Add a pre-release version
go get github.com/foo/bar@main
# go get updates go.mod:
# require github.com/stretchr/testify v1.8.4All lessons in this course
- Packages: Organizing Go Code
- Go Modules with go mod
- Adding External Dependencies
- Internal Packages and Workspaces