无法访问远程存储库以进行Go模块导入。

huangapple go评论68阅读模式
英文:

Unable to access remote repository for Go module import

问题

我需要能够从我公司的私有Gitlab存储库导入Go模块,但显然有些我没有理解的东西。

问题中的模块在我的go.mod文件顶部看起来像这样:

module gitlab.domain.company.com/path/to/repository

这是我的go env:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\E049839\AppData\Local\go-build
set GOENV=C:\Users\E049839\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\E049839\go\pkg\mod
set GONOPROXY=*.company.com
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\E049839\go
set GOPRIVATE=*.company.com
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\N\the_program\go.mod
set GOWORK=
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\E049839\AppData\Local\Temp\go-build416370598=/tmp/go-build -gno-record-gcc-switches

我只使用ssh来推送和拉取公司的Gitlab,所以我不知道为什么会出现问题,但这是我的.gitconfig文件:

insteadOf = https://gitlab.domain.company.com/
insteadOf = https://gitlab.company.com/

每次我尝试对该项目进行go buildgo get时,都会出现以下错误:

go: gitlab.domain.company.com/path/to/lib: 无法识别的导入路径 "gitlab.domain.company.com/path/to/lib": https fetch: Get "https://gitlab.domain.company.com/path/to/lib?go-get=1": dial tcp xx.xx.xxx.xxx:xxx: connectex: 由于目标计算机积极拒绝,无法建立连接。

一些信息已经被删除了。

我使用的Go版本是1.19,运行在Windows上。我已经尝试了各种方法来解决这个模块的问题,甚至考虑用一种具有合理版本控制的语言重写整个应用程序。

英文:

I need to be able to import Go modules from my company's private Gitlab repository, but there's something I'm very obviously not getting about how it works.

The module in question looks something like this at the top of my go.mod file:

module gitlab.domain.company.com/path/to/repository

Here's my go env:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\E049839\AppData\Local\go-build
set GOENV=C:\Users\E049839\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\E049839\go\pkg\mod
set GONOPROXY=*.company.com
set GONOSUMDB=*.company.com
set GOOS=windows
set GOPATH=C:\Users\E049839\go
set GOPRIVATE=*.company.com
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.19
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\N\the_program\go.mod
set GOWORK=
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\E049839\AppData\Local\Temp\go-build416370598=/tmp/go-build -gno-record-gcc-switches

I use ssh exclusively to push and pull from the company's Gitlab, so I don't know why that would be my issue, but here's my .gitconfig anyway:

insteadOf = https://gitlab.domain.company.com/
insteadOf = https://gitlab.company.com/

Any time I try to go build or go get for this project, I'm given this error:

go: gitlab.domain.company.com/path/to/lib: unrecognized import path "gitlab.domain.company.com/path/to/lib": https fetch: Get "https://gitlab.domain.company.com/path/to/lib?go-get=1": dial tcp xx.xx.xxx.xxx:xxx: connectex: No connection could be made because the target machine actively refused it.

Some info redacted obviously.

My version of Go is 1.19 running on Windows. I'm out of ideas trying to fool with this module, to the extent that I'm considering rewriting the entire application in a language with sensible version control.

答案1

得分: 1

你的 ssh URL 看起来有点奇怪。我的 GitHub URL 以前是 ssh:// 开头的。这个错误意味着它没有使用 ssh,所以它没有正确读取配置。

英文:

Your ssh url looks a little funky. My github one used to look like ssh://. That error means it is not using ssh, so it is not reading the config correctly.

答案2

得分: 1

在从GitLab项目中检索go模块时存在已知问题[1] [2],特别是那些位于子组中的项目。

在该问题中描述了一些解决方法(其中之一是您正在使用的方法),但这并不适用于所有情况,例如嵌套在“顶级组/项目”之外的子组。

对于自托管实例,您可以启用go代理,这也可以解决该问题。或者,如果您的项目直接位于顶级组下,也可以避免这个问题。

然而,在您的情况下,这似乎是一个配置错误,因为错误是一个网络问题(尽管您通常可以访问这些服务):

无法建立连接,因为目标计算机积极拒绝了连接

这是一个与gitlab或go get无关的网络错误。

英文:

There are known issues<sup>[1] [2]</sup> with retrieving go modules from gitlab projects, particularly those that reside within subgroups.

There's a few workarounds described in that issue (one of which you are using) but this does not work in all circumstances like subgroups nested beyond top-level-group/project.

For self-hosted instances you can enable the go proxy which also eliminates the problem. Or if you have your project directly under a top-level group, this will also avoid the problem.

In your case, however, this seems to be [additionally] a misconfiguration because the error is a networking issue (despite you being able to access these services normally):

> No connection could be made because the target machine actively refused it

This is a networking error not necessarily related to gitlab or go get...

答案3

得分: 1

我完全忘记了我的ssh配置了密码。现在我已经解决了这个问题,一切都很顺利。感谢所有为此做出贡献的人。我将保留这个建议,供将来遇到同样问题的人参考:如果你的ssh配置了密码,你需要考虑到它。在我的情况下,我能够直接删除密码,这可能不是最佳实践,但有效。

英文:

It had totally slipped my mind that my ssh was configured with a password. Now that I'm past that, it's working swimmingly. Thank you to everyone who contributed. I'm leaving this up as a suggestion to anyone experiencing the same issue in the future: if you have a password configured with ssh, you will have to account for it. In my case, I was able to just remove it, which is probably not best practice, but works.

答案4

得分: 0

请尝试在 %USERPROFILE%\.gitconfig 文件中使用相同的设置(将 ssh:/... 替换为 ssh://...)。

我不知道有一个名为 git.config 的文件。

英文:

Try the same setting (with ssh://... instead of ssh:/...) in %USERPROFILE%\.gitconfig.

I am not aware of a git.config file.

huangapple
  • 本文由 发表于 2022年8月19日 02:21:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/73407781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定