q Read about modules naming https://go.dev/doc/modules/managing-dependencies#naming_module
Module specifies dependencies needed to run the code, including the Go version and the set of other modules it requires.
Module is defined by go mod file.
All Go programs start from the main
function in the main
package.
As you add or improve functionality in your module, you publish new versions of the module.
Run the go mod init
command, giving it your module path — here, use example.com/greetings
. If you publish a module, this must be a path from which your module can be downloaded by Go tools. That would be your code’s repository.
Module has a path, e.g. example.com/greetings
. For a published module it must be a path from which it can be downloaded by Go tools ( this https://pkg.go.dev/golang.org/x/toolsq?) - your code’s repository.
CLI
go mod <command> [arguments]
provides access to operations on modules.
Commands:
download
- download modules to local cacheedit
- edit go.mod from tools or scriptsgraph
- print module requirement graphinit
- initialize new module in current directorytidy
- add missing and remove unused modulesvendor
- make vendored copy of dependenciesverify
- verify dependencies have expected contentwhy
- explain why packages or modules are needed
Target the module to a local dir:
go mod edit -replace example.com/greetings=../greetings
The built-in documentation:
Versioning
History
Modules were introduces in Go 1.11 and became the default build mode since 1.16. The use of GOPATH
is not recommended since then.