Common commands
go mod init # 初始化go.mod
go mod tidy # 更新依赖文件
go mod download # 下载依赖文件
go mod vendor # 将依赖转移至本地的vendor文件
go mod edit # 手动修改依赖文件
go mod graph # 打印依赖图
go mod verify # 校验依赖
Introduction to go module
Go module is the official go dependency management library that comes with go. It is officially recommended to use
go module in version 1.13 to organize all dependencies under a project (folder) into a go.mod file, which contains the version of the dependency, etc.
After using go module, we don't need to put the code under src
1. Project open go module
set GO111MODULE=on
2. Initialize the project
go mod init test(test为项目名)
A go.mod file will appear in the project root directory.
Note that the go.mod file at this time only identifies the project name and the version of go. This is normal because it is just initialized.
3. Test project dependencies
Set the geographic address first, the default proxy may fail to detect otherwise (restart the editor after modification)
https://goproxy.io/
go mod tidy
tidy will detect all imported dependencies in this folder and write them into the go.mod file. At this time, the dependencies are still not downloaded
4. Download project dependencies
We need to download the dependencies locally instead of using go get
go mod download
If you do not set GOPROXY as a domestic mirror, this step will be 100% to the death;
At this time, all dependencies will be downloaded to GOPATH, and a go.sum file will be generated in the root directory, which is the detailed dependency of the dependency
Congratulations! You're done here! ! !