如何从Dep迁移到Go模块 [英] How do I migrate from Dep to Go Modules
本文介绍了如何从Dep迁移到Go模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在使用Dep,并且想开始使用Go模块.
I'm currently using Dep and would like to start using Go modules.
如何迁移?
推荐答案
从Dep迁移到Go模块非常容易.
Migrating from Dep to Go Modules is very easy.
- 运行
go version
,并确保您使用的是Go 1.11版或更高版本. - 将代码移至GOPATH之外或设置
export GO111MODULE=on
. -
go mod init [module path]
:这将从Gopkg.lock导入依赖项. -
go mod tidy
:这将删除不必要的导入,并添加间接导入. - (可选)删除供应商文件夹(
rm -rf vendor/
或移至回收站) -
go build
:进行测试以查看其是否有效. -
rm -f Gopkg.lock Gopkg.toml
:删除用于Dep的过时文件.
- Run
go version
and make sure you're using Go version 1.11 or later. - Move your code outside of GOPATH or set
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.- (Optional) Delete your vendor folder (
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通过读取Gopkg.lock
文件从Dep导入了我的依赖项,并且还创建了go.mod
文件.
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
将您的依赖项复制到供应商文件夹中. - 运行
go build -mod=vendor
以确保go build
使用您的供应商文件夹.
- Run
go mod vendor
to copy your dependencies into the vendor folder. - Run
go build -mod=vendor
to ensurego build
uses your vendor folder.
这篇关于如何从Dep迁移到Go模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文