如何在 Go 项目中使用本地 Go 模块
How to use local Go module inside a Go project
在我们的本地网络中,我们有一个 GitLab 运行ning。 IP 绑定到 gitlab.local
。我有一个 go 包 http://gitlab.local/projectsmall/core
,它正在被另一个 Go 项目使用。在这个项目中,当我尝试 运行 go mod tidy
时,出现此错误:
go get gitlab.local/projectsmall/core:
unrecognized import path "gitlab.local/projectsmall/core"
(https fetch:
Get https://gitlab.local/projectsmall/core?go-get=1:
dial tcp 192.168.28.9:443:
connect: connection refused
)
我已将 id_rsa.pub
内容添加到 SSH Kyes。我尝试将此 core
项目添加到 mod 路径,如下所示:/Users/UserA/go/pkg/mod/gitlab.local/guxin/core
。使用 GoLand IDE import "gitlab.local/guxin/core"
仍然是红色的。似乎 go mod 项目找不到这个 gitlab.local/guxin/core
包。在 go.mod
文件中,在 require 块内,当我添加此 gitlab.local/guxin/core
时,IDE 警报:usage: require module/path
.
我不确定,但在我看来,问题可能出在您使用的是 ssh 密钥,并且您是通过 HTTPs 协议连接的,正如您从错误文本中看到的那样。
试一试:https://gist.github.com/dmitshur/6927554
$ ssh -A vm
$ git config --global url."git@gitlab.local:".insteadOf "https://gitlab.local/"
$ cat ~/.gitconfig
[url "git@gitlab.local:"]
insteadOf = https://gitlab.local/
$ go get gitlab.local/private/repo && echo Success!
Success!
还有:
What's the proper way to "go get" a private repository?
In GitLab, since the repositories always end in .git, I must specify
.git at the end of the repository name to make it work, for example:
import "example.org/myuser/mygorepo.git"
And:
$ go get example.org/myuser/mygorepo.git
Looks like GitHub solves
this by appending ".git".
我发现它使用的是https,但是本地gitlab没有使用SSL。所以我尝试了 go get -v -insecure
,现在可以使用了。
在我们的本地网络中,我们有一个 GitLab 运行ning。 IP 绑定到 gitlab.local
。我有一个 go 包 http://gitlab.local/projectsmall/core
,它正在被另一个 Go 项目使用。在这个项目中,当我尝试 运行 go mod tidy
时,出现此错误:
go get gitlab.local/projectsmall/core:
unrecognized import path "gitlab.local/projectsmall/core"
(https fetch:
Get https://gitlab.local/projectsmall/core?go-get=1:
dial tcp 192.168.28.9:443:
connect: connection refused
)
我已将 id_rsa.pub
内容添加到 SSH Kyes。我尝试将此 core
项目添加到 mod 路径,如下所示:/Users/UserA/go/pkg/mod/gitlab.local/guxin/core
。使用 GoLand IDE import "gitlab.local/guxin/core"
仍然是红色的。似乎 go mod 项目找不到这个 gitlab.local/guxin/core
包。在 go.mod
文件中,在 require 块内,当我添加此 gitlab.local/guxin/core
时,IDE 警报:usage: require module/path
.
我不确定,但在我看来,问题可能出在您使用的是 ssh 密钥,并且您是通过 HTTPs 协议连接的,正如您从错误文本中看到的那样。
试一试:https://gist.github.com/dmitshur/6927554
$ ssh -A vm
$ git config --global url."git@gitlab.local:".insteadOf "https://gitlab.local/"
$ cat ~/.gitconfig
[url "git@gitlab.local:"]
insteadOf = https://gitlab.local/
$ go get gitlab.local/private/repo && echo Success!
Success!
还有: What's the proper way to "go get" a private repository?
In GitLab, since the repositories always end in .git, I must specify .git at the end of the repository name to make it work, for example:
import "example.org/myuser/mygorepo.git"
And:
$ go get example.org/myuser/mygorepo.git
Looks like GitHub solves this by appending ".git".
我发现它使用的是https,但是本地gitlab没有使用SSL。所以我尝试了 go get -v -insecure
,现在可以使用了。