0PricingLogin
Go Academy · Lesson

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 driver

go 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.4

All lessons in this course

  1. Packages: Organizing Go Code
  2. Go Modules with go mod
  3. Adding External Dependencies
  4. Internal Packages and Workspaces
← Back to Go Academy