semantic import versioning: explicitly mention including '/vN' in 'go get' commands.

thepudds 2019-08-30 09:05:14 -04:00
parent 931cb01c0b
commit f0b0e16b97

@ -237,7 +237,7 @@ Recall [semver](https://semver.org/) requires a major version change when a v1 o
As a result of Semantic Import Versioning, code opting in to Go modules **must comply with these rules**:
* Follow [semver](https://semver.org/). (An example VCS tag is `v1.2.3`).
* If the module is version v2 or higher, the major version of the module _must_ be included as a `/vN` at the end of the module paths used in `go.mod` files (e.g., `module github.com/my/mod/v2`, `require github.com/my/mod/v2 v2.0.0`) and in the package import path (e.g., `import "github.com/my/mod/v2/mypkg"`).
* If the module is version v2 or higher, the major version of the module _must_ be included as a `/vN` at the end of the module paths used in `go.mod` files (e.g., `module github.com/my/mod/v2`, `require github.com/my/mod/v2 v2.0.1`) and in the package import path (e.g., `import "github.com/my/mod/v2/mypkg"`). This includes the paths used in `go get` commands (e.g., `go get github.com/my/mod/v2@v2.0.1`. Note there is both a `/v2` and a `@v2.0.1` in that example. One way to think about it is that the module name now includes the `/v2`, so include `/v2` whenever you are using the module name).
* If the module is version v0 or v1, do _not_ include the major version in either the module path or the import path.
In general, packages with different import paths are different packages. For example, `math/rand` is a different package than `crypto/rand`. This is also true if different import paths are due to different major versions appearing in the import path. Thus `example.com/my/mod/mypkg` is a different package than `example.com/my/mod/v2/mypkg`, and both may be imported in a single build, which among other benefits helps with diamond dependency problems and also allows a v1 module to be implemented in terms of its v2 replacement or vice versa.