Table of Contents
- Quick Start Example
- Semantic Import Versioning
- Define a Module
- Prepare for a Release
- Opening keynote: Go with Versions - GopherConSG 2018
Quick Start Example tutorial
module temp/hello require rsc.io/quote v1.5.2
- Modules must be semantically versioned in the form
v(major).(minor).(patch), such as
- If using Git, tag released commits with their versions.
- There are four directives:
replacedirectives only operate on the current (“main”) module.
All of the packages in a module share a common prefix – the module path. The
go.modfile defines the module path via the module directive. For example, if you are defining a module for two packages
example.com/my/project/bar, the first line in your
go.modfile typically would be module
example.com/my/project, and the corresponding on-disk structure could be:
project/ ├── go.mod ├── bar │ └── bar.go └── foo └── foo.go
Semantic Import Versioning discussion
- Follow semantic versioning (with tags such as
- If the module is version v2 or higher, the major version of the module must be included in both the module path in the go.mod file (e.g., module
example.com/my/mod/v2) and the package import path (e.g.,
- If the module is version
v1, do not include the major version in either the module path or the import path.
Define a Module howto
Most projects will follow the simplest approach of using a single module per repository, which typically would mean creating one go.mod file located in the root directory of a repository.
Prepare for a Release howto
go mod tidyto possibly prune any extraneous requirements
go test allto test your module
- Ensure your
go.sumfile is committed along with your
go.sumcontains the expected cryptographic checksums of the content of specific module versions.
- Note that
go.sumis not a lock file as used in some alternative dependency management systems.
Opening keynote: Go with Versions - GopherConSG 2018 tutoral
- The reasoning of the policy
- Packages should support backward minor-version compatibility.
- When there is a conflict, pick the minimum available version.
- Unless there is a version inconsistency, like cyclic dependencies or a situation in which the program cannot determine the minimum common version, even when some dependencies are updated, the compatibility and repeatability are maintained.