1.go mod 替代原来gopath的功能,依赖包下载依赖Go环境变量
1 | export GO111MODULE=on |
2.go mod init 一个golang 项目
- go mod 的命令使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15$ go help mod
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 - 用go mod 初始化glusterfs-benchmark依赖包管理
1 | //进入glusterfs-benchmark目录 |
- 项目目录架构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18[perrynzhou@Debian ~/Source/perryn/glusterfs-benchmark]$ tree ../glusterfs-benchmark/
../glusterfs-benchmark/
├── api
│ ├── fuse_fetch.go
│ └── glfs_fetch.go
├── conf
│ └── conf.go
├── go.mod
├── metric
│ └── metric.go
├── pkg
│ └── mod
│ └── cache
│ └── lock
└── utils
└── utils.go
14 directories, 114 files - 引入glusterfs-benchmark/api/fuse_fetch.go中引入utils库本地库
1 | // fuse_fetch.go的包信息 |
1 | //修改go.mod文件 |
- 项目构建
1
2
3
4
5
6//进入包含main.go的目录下执行go mod vendor,保存依赖包
go mod vendor
//下载第三方依赖库
go mod tidy -v
//编译项目
go build -mod=vendor