Skip to content

Go module

go.mod

  • The go.mod file defines a module.
  • It is created at the root of the project
  • Dependencies are added to go.mod automatically when running commands that fetches them, like go get, go build, go run
// go.mod

// module identifier
module github.com/username/myproject

// go version
go 1.20

// toolchain
toolchain go1.23.2

// explicit dependencies
require (
  github.com/some/dependency v1.5.2
  golang.org/x/tools v0.1.2
)

// implicit dependencies (need to be marked with the "indirect" comment)
require (
  dario.cat/mergo v1.0.1 // indirect
  github.com/BurntSushi/toml v1.4.0 // indirect
  github.com/Microsoft/go-winio v0.6.2 // indirect
)

go.sum

  • go.sum is a lock file to fixes a specific version by its checksum (hash)
  • Ensures the integrity and reproducibility