go get -v gitlab.xxxx.com/iphpt/commonPkg
go get gitlab.xxxx.com/iphpt/commonPkg: module gitlab.xxxx.com/iphpt/commonPkg: Get “https://proxy.golang.org/gitlab.xxxx.com/iphpt/commonPkg/@v/list”: dial tcp 34.64.4.17:443: i/o timeout
go get直接请求外包代理上去了,另外即使设置了代码,也肯定拉取不到的,因为这个包公司内网上的
export GOPRIVATE=gitlab.xxxx.com
进行 go env
查看,发现 GONOPROXY
,GONOSUMDB
,GOPRIVATE
都已经发生改变
go get -v gitlab.xxxx.com/iphpt/commonPkg
go get gitlab.xxxx.com/iphpt/commonPkg: unrecognized import path “gitlab.xxxx.com/iphpt/commonPkg”: https fetch: Get “https://gitlab.xxxx.com/iphpt/commonPkg?go-get=1”: dial tcp 101.9.183.187:443: connect: connection refused
go get 默认走https了
go get -v –insecure gitlab.xxxx.com/iphpt/commonPkg
go get gitlab.xxxx.com/iphpt/commonPkg: unrecognized import path “gitlab.xxxx.com/iphpt/commonPkg”: parse http://gitlab.xxxx.com/iphpt/commonPkg?go-get=1: no go-import meta tags (meta tag gitlab.xxxx.com/iphpt/commonPkg did not match import path gitlab.xxxx.com/iphpt/commonPkg)
嗯,这个问题就复杂了, 以上执行都在 已经让sre把gitlab的域名后的端口号给去掉了,也就是把 一个正常域名跳转到 带端口的服务下
就是在 包后面加上 .git
, 发现不报上面的错了,但是拉取还是不行,另外,拉取下来的话 文件目录也不太对,所以不进行尝试了
查看网上解决办法
上面的 no go-import meta tags
是因为gitlab没有返回或者没有请求到 gitlab的 meta标签, 所以让nginx做层跳转
if ($http_user_agent ~* "go") {
return 200 "<!DOCTYPE html><head><meta content='$host$uri git ssh://git@$host:$uri.git' name='go-import'></head></html>";
}
不过这方法还未实践,这两天找sre试试
在需要公共包的项目里新建一个 文件夹 privatePkg
cd privatePkg
git clone git@gitlab.xxxx.com/iphpt/commonPkg.git
cd commonPkg
rm -rf .git
cd ../../
git add .
然后修改 go.mod
require gitlab.xxxx.com/iphpt/commonPkg v0.0.0
replace gitlab.xxxx.com/iphpt/commonPkg => ./privatePkg/commonPkg
先这么用着吧!
我发现我可以拉取了.. 操作是
gitlab没有做任何改动, 不过需要注意的是 版本号不要打成 v0.0.01
这种, 可以打成 v0.0.1
这样
然后就是先把服务拉取到本地 mod 缓存里, 为了确保最新, 也可以先把本地缓存里先删掉, 再次拉取确定是否是正常的
比如 go mod download
如果是单独拉取这个 自己的私有的在内网的包
go get –insecure gitlab.xxxx.com/iphpt/commonPkg
这样还会报
go get gitlab.xxxx.com/iphpt/commonPkg: unrecognized import path "gitlab.xxxx.com/iphpt/commonPkg": parse http://gitlab.xxxx.com/iphpt/commonPkg?go-get=1: no go-import meta tags (meta tag gitlab.xxxx.com/iphpt/commonPkg did not match import path gitlab.xxxx.com/iphpt/commonPkg)
执行
go get –insecure gitlab.xxxx.com/iphpt/commonPk.git
go: downloading gitlab.xxxx.com/iphpt/commonPk.git v0.0.2
go: gitlab.xxxx.com/iphpt/commonPk.git upgrade => v0.0.2
go get: gitlab.xxxx.com/iphpt/commonPk.git@v0.0.2: parsing go.mod:
module declares its path as: gitlab.xxxx.com/iphpt/commonPk
but was required as: gitlab.xxxx.com/iphpt/commonPk.git
其实这样就是下载成功了, 在go mod 缓存里能看到了
然后你项目里设置
require gitlab.xxxx.com/iphpt/commonPk v0.0.2
replace gitlab.xxxx.com/iphpt/commonPk v0.0.2 => gitlab.xxxx.com/iphpt/commonPk.git v0.0.2
本站(PHP --> Golang)已重构,代码开源
当你能力不能满足你的野心的时候,你就该沉下心来学习