Package Management
The Deployment That Broke Everything
cannot find package "github.com/sirupsen/logrus"
in any of:
/usr/local/go/src/github.com/sirupsen/logrus (from $GOROOT)
/home/deploy/go/src/github.com/sirupsen/logrus (from $GOPATH)logrus==1.8.0What Are Go Modules?
Before Modules (The Dark Ages)
With Modules (The Light)
Creating Your First Module
Initialize a Module
Adding Your First Dependency
The go.sum File
Semantic Versioning in Go
Version Selection
Major Version Suffixes
Common go mod Commands
go mod init
go get
go mod tidy
go mod download
go mod verify
go mod graph
go mod why
Upgrading and Downgrading Dependencies
Check for Updates
Upgrade to Latest
Downgrade
Real Example: The Logging Library Upgrade
The Replace Directive
Replace with Local Path
Replace with Fork
Real Example: Patching a Bug
Vendor Directory
Why Vendor?
Creating Vendor Directory
Using Vendor
Should You Vendor?
Private Modules
Using Private Repositories
Authentication
Real Example: Internal Libraries
Real Example: Complete Project Setup
1. Initialize Project
2. Add Dependencies
3. Write Code
4. Clean Up
5. Final go.mod
go.mod6. Commit
Best Practices
1. Always Commit go.sum
2. Run go mod tidy Before Committing
3. Pin Versions in Production
4. Review Dependency Updates
5. Use GOPRIVATE for Private Repos
6. Minimal Dependencies
Your Challenge
Key Takeaways
What I Learned
Last updated