登录
首页 >  Golang >  Go问答

尽管 SSH 配置完成,为何 “go get” 始终采用 HTTPS?

来源:stackoverflow

时间:2024-02-25 20:45:29 149浏览 收藏

“纵有疾风来,人生不言弃”,这句话送给正在学习Golang的朋友们,也希望在阅读本文《尽管 SSH 配置完成,为何 “go get” 始终采用 HTTPS?》后,能够真的帮助到大家。我也会在后续的文章中,陆续更新Golang相关的技术文章,有好的建议欢迎大家在评论留言,非常感谢!

问题内容

我已经正确配置了 ssh,我可以通过 ssh 使用我们的私人存储库执行 git 操作。但是当我使用 go getgo test (对于 go 模块)进行测试时,cli 不使用 ssh,而是使用 https。

.gitconfig

[url "ssh://[email protected]:7999"]
    insteadof = https://bitbucket.company.com/scm

~/.ssh/config

host bitbucket.company.com
 user git
 port 7999
 identityfile ~/.ssh/id_rsa

测试 ssh 是否有效

$ git ls-remote ssh://[email protected]:7999/project/repo.git
ab86e12ab20775a308b7d0b003ba562263fbfa23        head
ab86e12ab20775a308b7d0b003ba562263fbfa23        refs/heads/master
ab86e12ab20775a308b7d0b003ba562263fbfa23        refs/tags/v0.0.1

测试 go get

$ go get -v bitbucket.company.com/project/repo
go get bitbucket.company.com/project/repo: unrecognized import path "bitbucket.company.com/project/repo": https fetch: get "https://bitbucket.company.com/project/repo?go-get=1": dial tcp 10.68.204.3:443: connectex: a connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

go版本

go version go1.14.1 windows/amd64

进入环境

set GO111MODULE=on
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\sailhenz\AppData\Local\go-build
set GOENV=C:\Users\sailhenz\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=none
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\sailhenz\Documents\Development\Go
set GOPRIVATE=*.company.com
set GOPROXY=https://goproxy.io,direct
set GOROOT=C:\Users\sailhenz\Documents\Software\go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=C:\Users\sailhenz\Documents\Software\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\sail~1\AppData\Local\Temp\go-build227330694=/tmp/go-build -gno-record-gcc-switches

我错过了任何设置/配置吗? 提前致谢。


解决方案


尝试:

[url "bitbucket.company.com:"]
    insteadOf = https://bitbucket.company.com/

这会将任何 https://bitbucket.company.com/ 转换为 bitbucket.company.com: ,然后:

  • 被解释为 ssh url
  • 解码(通过 ~/.ssh/config)为 ssh://[email protected]:7999/...

关键是单独使用 bitbucket.company.com,它是 ~/.ssh/config 文件中的主机条目,意味着它将引用正确的私钥文件。

subham sarkar 报告 in the comments 关于 golang/go issue 27344

上面提到的解决方案似乎不适用于 go 1.13,并且在 go 1.14 中处于“积压”状态。

检查测试相同的 go get 是否适用于 go 1.11。

the comments issue 27254 中提到了 OP sailhenz

cmd/go:自定义导入路径私有存储库需要特殊配置

票证添加:

go get -x private.repo.net/user/package 是调试此问题的好方法。

以上就是《尽管 SSH 配置完成,为何 “go get” 始终采用 HTTPS?》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>