我们都知道在使用Golang时开发程序时都需要在 GOPATH 下面,这就非常不方便。如果你想放在磁盘上的其他地方,那么go mod将是你的“好伙伴”。
关于 go mod 的说明,可以参考:
命令行说明
➜ ~ go mod
Go mod provides access to operations on modules.
Note that support for modules is built into all the go commands, not just 'go mod'. For example, day-to-day adding, removing, upgrading, and downgrading of dependencies should be done using 'go get'.
See 'go help modules' for an overview of module functionality.
Usage: go mod <command> [arguments]
The commands are:
download --> download modules to local cache 下载依赖的 module 到本地 cache
edit --> edit go.mod from tools or scripts 编辑 go.mod graph print module requirement graph 打印模块依赖图
init --> initialize new module in current directory 在当

本文介绍了如何告别GOPATH,使用go mod进行Golang项目的包管理。通过更新Go版本到1.11以上,设置GO111MODULE环境变量为ON,执行`go mod init`初始化项目,生成go.mod和go.sum文件。`go mod verify`命令可检查依赖是否完整。go mod使得在非GOPATH目录下开发和管理依赖变得简单。
最低0.47元/天 解锁文章
805

被折叠的 条评论
为什么被折叠?



