Go Modules with go mod
Initializing modules, go.mod, go.sum
What Is a Go Module?
A module is a collection of Go packages with a go.mod file at its root. Modules are the unit of code distribution and versioning in Go:
// go.mod — created with: go mod init github.com/myuser/myapp
module github.com/myuser/myapp
go 1.21
require (
github.com/gin-gonic/gin v1.9.1
golang.org/x/sync v0.5.0
)go mod init
Initialize a new module with go mod init:
# In project directory:
go mod init github.com/myuser/myapp
# This creates go.mod:
# module github.com/myuser/myapp
# go 1.21
# The module path is the canonical import path prefix
# for all packages in this moduleAll lessons in this course
- Packages: Organizing Go Code
- Go Modules with go mod
- Adding External Dependencies
- Internal Packages and Workspaces