➜ ~ 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 edit edit go.mod from tools or scripts graph print module requirement graph init initialize new module in current directory tidy add missing and remove unused modules vendor make vendored copy of dependencies verify verify dependencies have expected content why explain why packages or modules are needed
Use "go help mod <command>" for more information about a command.
go mod download: 下载依赖的module到本地cache
go mod edit: 编辑go.mod
go mod graph: 打印模块依赖图
go mod init: 在当前目录下初始化go.mod(就是会新建一个go.mod文件)
go mod tidy: 整理依赖关系,会添加丢失的module,删除不需要的module
go mod vender: 将依赖复制到vendor下
go mod verify: 校验依赖
go mod why: 解释为什么需要依赖
在新项目中使用
使用go mod并不要求你的项目源码放到$GOPATH下,所以你的新项目可以放到任意你喜欢的路径。在项目根目录下执行go mod init,会生成一个go.mod文件。然后你可以在其中增加你的依赖,如下: