引言
golang使用微服务架构或者引用自封装的kit包,都会涉及到对于私有仓库的引用。 但是引用私有仓库或多或少会遇到一些问题,以下是一些问题的总结。
go get 私有仓库 或者 proxy 问题
gitlab.xxxx.com/xxxx/xxxx@v1.0.23: verifying module: gitlab.xxxx.com/xxxx/xxxx@v1.0.23: reading https://goproxy.cn/sumdb/sum.golang.org/lookup/gitlab.xxxx.com/xxxx/xxxx@
v1.0.23: 404 Not Found
server response: not found: gitlab.xxxx.com/xxxx/xxxx@v1.0.23: unrecognized import path "gitlab.xxxx.com/xxxx/xxxx": reading https://gitlab.xxxx.com/xxxx/xxxx@v1.0.23?go
-get=1: 403 Forbidden
解决方法
设置GOPRIVATE(go version >= 1.13),声明指定域名为私有仓库,go get在处理该域名下的所有依赖时,会直接跳过GOPROXY。
go env -w GOPRIVATE="gitlab.xxxx.com"
强制go get针对github.com与gitlab.com使用ssh而非https。
vim ~/.gitconfig
[url "git@gitlab.xxxx.com:"]
insteadOf = https://gitlab.xxxx.com/
module declares its path as
原因是go.mod没有使用如下格式进行module,引用仓库需命名为如下格式:
module gitlab.xxxx.com/xxxx/xxxx