Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

godeps - How do I migrate from Dep to Go Modules

I'm currently using Dep and would like to start using Go modules.

How do I migrate?

question from:https://stackoverflow.com/questions/55664630/how-do-i-migrate-from-dep-to-go-modules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Migrating from Dep to Go Modules is very easy.

  1. Run go version and make sure you're using Go version 1.11 or later.
  2. Move your code outside of GOPATH or set export GO111MODULE=on.
  3. go mod init [module path]: This will import dependencies from Gopkg.lock.
  4. go mod tidy: This will remove unnecessary imports, and add indirect ones.
  5. (Optional) Delete your vendor folder (rm -rf vendor/ or move to trash)
  6. go build: Do a test build to see if it works.
  7. rm -f Gopkg.lock Gopkg.toml: Delete the obsolete files used for Dep.

Go has imported my dependencies from Dep by reading the Gopkg.lock file and also created a go.mod file.

If you want to keep your vendor folder:

  1. Run go mod vendor to copy your dependencies into the vendor folder.
  2. Run go build -mod=vendor to ensure go build uses your vendor folder.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...