如何解决去获取私人包裹时无法读取用户名
我有一个 Go 项目,它使用托管在 github 中的私有库。目前正在使用 go 模块,所以我通过 SSH 配置了对 github 的访问,这样我就可以使用 go get github.com/myorg/mylibrary
这以前是有效的,但是现在我再次这样做时会收到下一条消息 go get github.com/myorg/mylibrary@commitId
:
github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: verifying module:
github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: reading https://sum.golang.org/lookup/github.com/!myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: 410 Gone
server response:
not found: github.com/myorg/mylibrary@v5.2.1-0.20210110224145-108714b2f88c: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/b186106557bfd44bc932dd151f0fcd2758d8d89d09ab32f8915de7f151e393d1: exit status 128:
fatal: could not read Username for 'https://github.com': terminal prompts disabled
我已经尝试过:
env GIT_TERMINAL_PROMPT=1 go get github.com/myorg/mylibrary@commitId
但还是一样。那么,为什么会得到这个?我怎样才能克服它?
解决方法
你可以使用 ssh + 公钥访问带有 go 模块的 github 私有项目
先将 git HTTP 方案替换为 ssh 方案
git config -e
// if you want replace scheme with global config use --global
git config --global -e
然后添加以下行
[url "git@github.com:"]
insteadOf = https://github.com
确保你的公钥已经添加到github
cat ~/.ssh/id_rsa.pub
// if file not found use ssh-keygen to generate it
ssh-keygen
在网址下面添加github访问的公钥添加
https://github.com/settings/keys
现在你可以在 go mod 中获取 github 私有项目
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。