# 创建项目目录mkdir module-namecd module-name# 初始化modulego mod init module-name# 查看生成的modcat go.mod# 查看项目结构和依赖tree -L 1 .# 第一次运行会自动检查代码里的第三方依赖包,并下载项目依赖的包go run main.go# 执行go help mod可以查看到以下子命令go help mod download download modules to local cache # 下载模块包到本地缓存 edit edit go.mod from tools or scripts # 从工具或脚本中修改go.md内容(暂时没觉得很好用) 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 # 将依赖拷贝到vendor中(会将依赖打包到当前目录下的vendor目录) verify verify dependencies have expected content # 检查依赖内容 why explain why packages or modules are needed # 解释为什么哪些包或者模块被需要
$ go get -u google.golang.org/grpcpackage google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)$ git clone https://github.com/grpc/grpc-go.git $GOPATH/src/google.golang.org/grpcgo mod edit -replace=google.golang.org/grpc=github.com/grpc/grpc-go@latestgo mod tidygo mod vendorgo build -mod=vendor
module <your module name>require ( google.golang.org/grpc v1.27.0)
go mod edit -require=github.com/LonelyPale/goutils@mastergo mod edit -require=golang.org/x/net@mastergo mod edit -require=golang.org/x/net@latest
参考: