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 cache
  • edit - edit go.mod from tools or scripts
  • graph - print module requirement graph
  • init - initialize new module in current directory
  • tidy - add missing and remove unused modules
  • vendor - make vendored copy of dependencies
  • verify - verify dependencies have expected content
  • why - 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:

go help mod
go help mod init

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.

References