如何在Go项目中使用本地Go模块

时间:2019-04-30 08:07:35

标签: go go-modules

在我们的本地网络中,我们正在运行一个GitLab。 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

2 个答案:

答案 0 :(得分:0)

我发现它使用的是https,但是本地gitlab没有使用SSL。所以我尝试了go get -v -insecure,它现在可以正常工作。

答案 1 :(得分:-1)

我不确定,但是在我看来,问题可能出在您使用的是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?

  

在GitLab中,由于存储库始终以.git结尾,因此我必须指定   存储库名称末尾的.git使其起作用,例如:

     

import "example.org/myuser/mygorepo.git"

     

并且:

     

$ go get example.org/myuser/mygorepo.git

     

看起来像GitHub可以解决   通过添加“ .git”来实现。

相关问题