The Go toolchain has a built-in system for managing version sets of related packages, called modules. The module was introduced in Go 1.11 and has been in production since 1.14.
To create a project using modules, run Go Mod init. This command creates a go.mod file that keeps track of dependent versions.
go mod init example.com/project
Copy the code
To add, upgrade, or degrade dependencies, run Go Get.
go get golang.org/x/text@v03.. 5
Copy the code
See tutorial: Creating modules for more information on getting started.
See Developing modules for guidance on how to use modules to manage dependencies.
Packages in modules should be backward compatible as they evolve, following import compatibility rules.
If an old package has the same import path as a new package. The new package must be backward compatible with the old package.Copy the code
The compatibility guidelines for Go 1 are a good reference here: do not remove exported names, encourage the use of tagged compound characters, and so on. If a different feature is needed, add a new name instead of changing an old one.
Modules are compiled with semantic versioning and semantic import versioning. If compatibility needs to be broken, release the module in a new major release. Modules with major version 2 and above require a major version suffix as part of their path (such as /v2). This preserves the import compatibility rule that packages of different major versions of a module have different paths.
Golang Foreign Language Translation project golang.org/doc/faq#get…