在我的一个项目中,我使用了一个内部模块:
package main
import (
"gitlab.example.com/team/project/internal/exitcodes"
)
效果很好。
现在我在另一个项目中也需要该模块,但我未能实现。
首先,我创建了一个新的存储库,在其中放置模块:gitlab.example.com/team/gocommon
并将导入相应更改为“gitlab.example.com/team/gocommon/exitcodes”。
然后我创建了一个accesstoken并将其放入~/.netrc
machine gitlab.example.com
login gogettoken
password DBJMsPsGrFAiMq2MDRRT
但是项目无法构建:
gitlab.example.com/team/gocommon/exitcodes: gitlab.example.com/team/[email protected]: verifying module: gitlab.example.com/team/[email protected]: reading https://sum.golang.org/lookup/gitlab.example.com/team/[email protected]: 404 Not Found
server response:
not found: gitlab.example.com/team/[email protected]: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/5c5d3cb0b00b8d48278234b7d0c82797966117d16c9fedbd2cf87e471d549e5b: exit status 128:
fatal: could not read Username for 'https://gitlab.example.com': terminal prompts disabled
Confirm the import path was entered correctly.
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
我已经检查了提到的 golang.org 链接,但它并没有帮助我找到解决方案。
看起来您在使用 ssh git 和 https git 时遇到问题。你们公司有人已经这样做了吗?可能存在一些安全问题。
检查一些没有顺序的东西,这个列表中的任何一个都可能对你有帮助:
go mod tidy
go get <package>