off by default • 2016: vendor on by default • 2017: vendor always on Timeline • Before: GOPATH + go get • 2013: Godep • 2014: glide, gopkg.in • 2015: govendor • 2018: vgo/go module Tools • Godep: originally about reproducibility, restore/save your GOPATH • gopkgin.in: putting version information in the URL • gom, glide: modeled after tools in other languages • the vendor directory • go module with MVS https://about.sourcegraph.com/go/the-new-era-of-go-package-management
packages if that already in local. ▷ got get -u upgrades all indirect packages to the latest version. ▷ That may broke go build and cause your program unexpected behavior! https://research.swtch.com/vgo-mvs
new version of godep) save list and copy dependencies into Godeps go run the go tool with saved dependencies get download and install packages with specified dependencies path print GOPATH for dependency code restore check out listed dependency versions in GOPATH update update selected packages or the go version diff shows the diff between current and previously saved set of dependencies version show version info
import "gopkg.in/user/pkg.v3" → github.com/user/pkg (branch/tag v3, v3.N, or v3.N.M) For clarity, assuming a repository containing the following tags or branches: • v1 • v2.0 • v2.0.3 • v2.1.2 • v3 • v3.0 The following selectors would be resolved as indicated: • pkg.v1 → tag or branch v1 • pkg.v2 → tag or branch v2.1.2 • pkg.v3 → tag or branch v3.0 http://labix.org/gopkg.in
build will search packages in vendor directory before the real GOPATH. ▷ Go 1.5 introduced as experiment ▷ Go 1.6 default on ▷ Go 1.7 always on https://blog.wu-boy.com/2016/05/package-management-for-golang-glide/
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
Store all dependency modules to vendor/ ▷ $ go build -mod vendor ◦ Build with vendor/ ◦ It’s no more default behavior of go build https://roberto.selbach.ca/intro-to-go-modules/
indirect dependent module ▷ It only shows when you change the default version of the module like upgrade or downgrade ▷ Override go.mod settings of indirect modules
compatible ▷ Treat different major versions of same module as different modules ▷ They can be imported at the same time ▷ import "github.com/russross/blackfriday" => v1.x.x ▷ import blackfridayV2 "github.com/russross/blackfriday/v2" => v2.x.x ▷ import blackfridayV3 "github.com/russross/blackfriday/v3" => v3.x.x https://research.swtch.com/vgo-import