I'm currently using Dep and would like to start using Go modules.
How do I migrate?
A Module is a collection of Go packages stored in a file tree under $GOPATH/pkg folder with a go. mod file at its root. This file defines the module's path, which is also the import path used for your project, and its dependency requirements, which are the other modules needed for a successful build.
Migrating from Dep to Go Modules is very easy.
go version
and make sure you're using Go version 1.11 or later.export GO111MODULE=on
.go mod init [module path]
: This will import dependencies from Gopkg.lock.go mod tidy
: This will remove unnecessary imports, and add indirect ones.rm -rf vendor/
or move to trash)go build
: Do a test build to see if it works.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:
go mod vendor
to copy your dependencies into the vendor folder.go build -mod=vendor
to ensure go build
uses your vendor folder.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With