- package (no
go.mod
) != module (hasgo.mod
)
--
- to init module
go mod init example.com/hello
# creates `go.mod`
--
- to download dependencies
- and to remove unused dependencies
go mod tidy
- now both direct and indirect (
// indirect
) dependencies are ingo.mod
?
--
- to see dependencies
go list -m all
# filter?
go list -m rsc.io/q...
- to list available version
go list -m -versions rsc.io/sampler
--
- to upgrade module
# latest (default is @latest)
go get golang.org/x/text
# specific version
go get rsc.io/sampler@v1.3.1
- to upgrade dependencies of module
go get -u rsc.io/quote/v3
# go get: upgraded rsc.io/sampler v1.3.1 => v1.99.99
From go help get
:
The -u flag instructs get to update modules providing dependencies of packages named on the command line to use newer minor or patch releases when available.
--
- the
v3
inrsc.io/quote/v3
represents a different major version (not backward compatible)- convention is known as Semantic Import Versioning
The go command allows a build to include at most one version of any particular module path, meaning at most one of each major version: one rsc.io/quote, one rsc.io/quote/v2, one rsc.io/quote/v3, and so on.
This gives module authors a clear rule about possible duplication of a single module path: it is impossible for a program to build with both rsc.io/quote v1.5.2 and rsc.io/quote v1.6.0.
--
- to understand why a package is used
go mod why -m rsc.io/quote/v3
or
go mod graph | grep rsc.io/quote/v3
--
- import path checking is disabled when using module / vendor
Pseudo-versions are a special type of pre-release version. Pseudo-versions are useful when a user needs to depend on a project that has not published any semantic version tags, or develop against a commit that hasn’t been tagged yet, but users should not assume that pseudo-versions provide a stable or well-tested API.