q Go through go.mod reference https://go.dev/doc/modules/gomod-ref
Go module is defined by this file.
It contains the name of the module, Go version and list of all the dependencies and their versions.
Example:
module example.com/greetings
go 1.22.2
To init run the go mod init
command, e.g. go mod init example.com/greetings
.
Don’t edit the file directly. Instead use commands like go get
and go mod tidy
.
Directives
require`
Declares the module as a dependency to the current module, specifying the minimum module version.
Syntax: require module-path module-version
If the module isn’t published, the pseudo-version number is used, e.g.:
module example.com/hello
go 1.22.2
replace example.com/greetings => ../greetings
require example.com/greetings v0.0.0-00010101000000-000000000000
For a published module a tagger version number will be used:
require example.com/greetings v1.1.0