1.go mod 替代原来gopath的功能(可能理解有误)
2.go mod init 一个golang 项目
- go mod 的命令使用
$ 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
- glusterfs-benchmark项目信息
···
//进入glusterfs-benchmark目录
cd glusterfs-benchmark
go mod init glusterfs-benchmark
//会在 lusterfs-benchmark目录中 生成go.mod的文件
···
- 项目目录架构
[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库本地库
// fuse_fetch.go的包信息
package api
import (
"bufio"
"fmt"
utils "github.com/perryn/glusterfs-benchmark/utils"
"os"
"path/filepath"
"sync"
)
//修改go.mod文件
module glusterfs-benchmark
go 1.14
//新增这个命令
replace github.com/perryn/glusterfs-benchmark => ../glusterfs-benchmark
require github.com/perryn/glusterfs-benchmark v0.0.0-00010101000000-000000000000
//goland中去go get这个包后go.mod内容会自动添加如下信息
require github.com/perryn/glusterfs-benchmark v0.0.0-00010101000000-000000000000
有疑问加站长微信联系(非本文作者)