go module 引用码云(或其他私有仓库)的配置
go1.13开始引入了go mod包管理。go1.16开始默认开启go mod,以下总结在使用go mod 时,引用私有仓库或本地仓库出现的问题。此处以windows环境为例,Linux操作类似。
私有仓库(如码云/gitlab)
首先要保证配置过ssh私钥,即通过git可以直接拉取到私有仓库。
系统环境变量中加入GOPRIVATE变量,值为要过滤的私有地址,如*gitee.com。此处配置作用是通过代理拉取module时过滤掉码云的地址,不通代理拉取私有仓库地址。
此时项目中已经可以正常拉取私有仓库
PS D:\go\src\test\TESTS\test43> go mod init
go: creating new go.mod: module test/TESTS/test43
go: to add module requirements and sums:
go mod tidy
PS D:\go\src\test\TESTS\test43> go mod tidy
go: finding module for package gitee.com/xxxxx/xxxxx
go: found gitee.com/xxxxx/xxxxx in gitee.com/xxxxx/xxxxx v0.0.0-20200805075307-22c2dee8df32
go.mod文件:
module test/TESTS/test43
go 1.16
require gitee.com/xxxxx/xxxxx v0.0.0-20200805075307-22c2dee8df32