我有一个私有仓库,我的main.go
文件导入了它。当我进行go build时,出现以下错误:
找不到路径所对应的模块
对于私有仓库,我需要做些特殊的处理吗?我已经搜索过谷歌,但没有找到任何好的信息。使用dep时工作正常。
做这个
git config --global --add url."git@your-repo.com:".insteadOf "https://your-repo.com/"
export GOPRIVATE='your-repo.com'
确保你通过ssh进行的git克隆工作正常。
我从这个SO问题中复制了答案。
我在Medium上写了一个解决方案:使用私有Git存储库的Go模块。
我们处理它的方式基本与Alex Pliutau的答案相同,该博客提供了更详细的示例,说明如何使用来自GitHub / GitLab / BitBucket的令牌设置您的git配置。 它还提供了一个使用私有存储库的模块的工作Dockerfile示例。
GitLab的相关部分:
git config --global \
url."https://oauth2:${personal_access_token}@privategitlab.com".insteadOf \
"https://privategitlab.com"
#or
git config --global \
url."https://${user}:${personal_access_token}@privategitlab.com".insteadOf \
"https://privategitlab.com"
我希望它有帮助。
ssh-add -K ~/.ssh/id_rsa
-K
标志。 - Alexis Wilke$GOPATH
的“适当”位置并像任何其他项目一样使用源代码管理(例如git)。添加SSH密钥就像Rodrigo的答案一样很好,但是如果您已经在积极开发私有仓库,将其克隆到正确的目录不是与能够使用go get
相比一个困难的步骤。cd
到$GOHOME/src/github.com/git-username-for-repo
,然后git clone the-repo
。
your-repo
的示例吗? - undefinedgitlab.com
- undefined