Go Modules: Modern Dependency Management for Go
How to manage dependencies efficiently in Go using go.mod and go.sum.
1 Loading...
Go Modules: Modern Dependency Management for Go
In the early days of Go, we used GOPATH. It was… opinionated. Today, Go Modules are the standard.
Usage
Start a module:
go mod init github.com/username/myproject
This creates a go.mod file.
Add a dependency:
go get github.com/gin-gonic/gin
go.sum
Go relies on the checksum database to ensure security. go.sum contains cryptographic hashes of your module’s content to ensure no one tampered with the code you are downloading.
Tidy
The most used command:
go mod tidy
This ensures go.mod matches the source code in your module. It adds missing modules and removes unused ones.
Conclusion
Go modules are simple, built-in, and fast. They solve versioning without complex configuration files.