I'm currently using Dep and would like to start using Go modules.
How do I migrate?
I'm currently using Dep and would like to start using Go modules.
How do I migrate?
On
To add to @Nicholas answer's:
Here is from the offical golang documenation:
To create a go.mod for an existing project:
$ export GO111MODULE=on # manually active module mode
$ cd $GOPATH/src/<project path> # e.g., cd $GOPATH/src/you/hello
$ go mod init
This step converts from any existing dep Gopkg.lock file or from any of the other nine total supported dependency formats, adding require statements to match the existing configuration.
$ go build ./...
$ go test ./...
(Optional) Run the tests for your module plus the tests for all direct and indirect dependencies to check for incompatibilities:
$ go test all
On
Another way to upgrade to modules.
Remove the Gopkg.toml and Gopkg.lock
rm Gopkg.*
Initialise the Go modules
GO111MODULE=on go mod init
Run go mod tidy to pull all the indirect modules and remove unused modules
GO111MODULE=on go mod tidy
Run build to ensure everything works fine
go build
Tip in case you face few modules not found then manually update the modules tag in go.mod file.
Migrating from Dep to Go Modules is very easy.
go versionand 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.lockfile and also created ago.modfile.If you want to keep your vendor folder:
go mod vendorto copy your dependencies into the vendor folder.go build -mod=vendorto ensurego builduses your vendor folder.