我现在正在为我的协作项目使用私有存储库。
我像gitlab.xity.dev/QuietJoon/testgoget一样设置了我的个人GitLab,
我试着为我的团队提供它。
(对于此问题,存储库https://gitlab.xity.dev/QuietJoon/testgoget是公开的)
问题
然而,当我尝试go get -v gitlab.xity.dev/QuietJoon/testgoget时,
上面写着
get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
package gitlab.xity.dev/QuietJoon/testgoget: cannot download, http://gitlab.xity.dev/QuietJoon/testgoget.git uses insecure protocol另外,我尝试了带有显式.git后缀的go get -v gitlab.xity.dev/QuietJoon/testgoget.git,结果得到
# cd .; git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget
fatal: repository 'https://gitlab.xity.dev/QuietJoon/testgoget/' not found
# cd .; git ls-remote git+ssh://gitlab.xity.dev/QuietJoon/testgoget您可以看到go get先尝试https,
但是go get的后缀是.git,所以它说找不到存储库,并前进到下一个git+ssh协议。我可以在没有任何身份验证过程的情况下获得git clone gitlab.xity.dev/QuietJoon/testgoget.git,
git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget.git
c238e4b9818eabe6309a2c5cf274808ec39bf7d5 HEAD
c238e4b9818eabe6309a2c5cf274808ec39bf7d5 refs/heads/master我的不完整解决方案
在我设置了全局git重定向配置之后(如git config --global url."https://gitlab.xity.dev".insteadOf "http://gitlab.xity.dev")
我可以拿到带有-insecure标志的包
$ go get -v -insecure gitlab.xity.dev/QuietJoon/testgoget
get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
gitlab.xity.dev/QuietJoon/testgoget (download)
gitlab.xity.dev/QuietJoon/testgoget当我没有提供像这样的http://gitlab.xity.dev/QuietJoon/testgoget时
$ curl -I http://gitlab.xity.dev/QuietJoon/testgoget
HTTP/1.1 404 Not Found
Server: nginx/1.16.0
Date: Tue, 09 Jun 2020 06:16:25 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
$ curl -I http://gitlab.xity.dev/QuietJoon/testgoget.git
HTTP/1.1 404 Not Found
Server: nginx/1.16.0
Date: Tue, 09 Jun 2020 06:17:30 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive
$ git clone http://gitlab.xity.dev/QuietJoon/testgoget
Cloning into 'testgoget'...
fatal: repository 'http://gitlab.xity.dev/QuietJoon/testgoget/' not found
$ git clone http://gitlab.xity.dev/QuietJoon/testgoget.git
Cloning into 'testgoget'...
fatal: repository 'http://gitlab.xity.dev/QuietJoon/testgoget.git/' not found是的,这可能是可行的,因为go get使用git clone,而当协议不安全时,go get会在给定的url中添加.git后缀。
其他解决方案
我可以通过在%GOPATH%/src手动使用git clone来解决这个问题。
然而,这不是我个人的项目,而是合作项目。
因此,我不能告诉每个人都这样做。(因为我和其他人都是Golang初学者)
我只想用普通的Golang方式*只用import "gitlab.xity.dev/XXX/YYY"。(import "gitlab.xity.dev/XXX/YYY.git"对Golang来说似乎也是不好的方式),*不是自己手动git重定向配置和go get -insecure
问题
1.如何帮助go get访问https而不是http
我调查了许多帮助,比如像this这样的问答,并添加了像这样的全局git配置
[url "https://gitlab.xity.dev"]
insteadOf = http://gitlab.xity.dev但在没有-insecure标志的情况下,这并不能正确地帮助go get。
我知道go get从来没有意识到有这样的git配置。
那么,我如何帮助go get更喜欢尝试https而不是http呢
2.为什么go get说它不喜欢访问不安全的协议,但它更喜欢访问http而不是https?
甚至go get也在抱怨不安全的协议,为什么它一开始不尝试访问https而不是http
我不确定这是不是go get的bug。
3.为什么我显式地给出后缀.git,go get还要去掉它?
当我显式地给出.git后缀时,go get丢弃了给定的后缀,并说它无法正确地找到存储库。
$ go get -v gitlab.xity.dev/QuietJoon/testgoget.git
# cd .; git ls-remote https://gitlab.xity.dev/QuietJoon/testgoget
fatal: repository 'https://gitlab.xity.dev/QuietJoon/testgoget/' not found但是您可以看到,当go get尝试不安全的协议时,它不需要显式的.git
$ go get -v gitlab.xity.dev/QuietJoon/testgoget
get "gitlab.xity.dev/QuietJoon/testgoget": found meta tag get.metaImport{Prefix:"gitlab.xity.dev/QuietJoon/testgoget", VCS:"git", RepoRoot:"http://gitlab.xity.dev/QuietJoon/testgoget.git"} at //gitlab.xity.dev/QuietJoon/testgoget?go-get=1
package gitlab.xity.dev/QuietJoon/testgoget: cannot download, http://gitlab.xity.dev/QuietJoon/testgoget.git uses insecure protocol是什么造成了不同?
条件和环境
我已经将gitlab.xity.dev的GOPRIVATE设置为
go env
...
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=gitlab.xity.dev
set GONOSUMDB=gitlab.xity.dev
set GOOS=windows
set GOPATH=t:\go
set GOPRIVATE=gitlab.xity.dev
set GOPROXY=https://proxy.golang.org,direct
set GOSUMDB=sum.golang.org
...我认为在这种情况下还没有使用GOPRIVATE。
发布于 2020-06-09 22:05:15
问题出在你的git服务器上。Go get将获取所需的模块,并将尝试使用https来获取它。如果你尝试一下:curl https://gitlab.xity.dev/QuietJoon/testgoget.git。你会得到一个302:<html><body>You are being <a href="http://gitlab.xity.dev/QuietJoon/testgoget">redirected</a>.</body></html>
如果你不能用go改变你的服务器gitconfig,那么get insecure就是你最好的选择。
https://stackoverflow.com/questions/62276763
复制相似问题