How to install a go library from github without public key?

huangapple go评论65阅读模式
英文:

How to install a go library from github without public key?

问题

我想安装gqrcode项目,并从该项目获取以下安装说明:

go get -u github.com/KangSpace/gqrcode

在执行此命令时,我首先遇到了以下问题:

...

fatal: could not read Username for 'https://github.com': terminal prompts disabled

...

在执行以下命令后:

git config --global --add url."git@github.com:".insteadOf "https://github.com/"

我得到了以下错误信息:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
package github.com/KangSpace/gqrcode: exit status 1

在其他语言(如Python)中,我可以先克隆库(git clone ....),然后再安装它。

在Go语言中,我该如何执行类似的操作?

英文:

I want to install the gqrcode project and get from that project the following installation instructions:

go get -u github.com/KangSpace/gqrcode

When performing this, I first got:

...

fatal: could not read Username for 'https://github.com': terminal prompts disabled

...

After performing

git config --global --add url."git@github.com:".insteadOf "https://github.com/"

I get:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
package github.com/KangSpace/gqrcode: exit status 1

In other languages like python I can clone the library first (git clone ....) and afterwards install it.

How can I perform something similar in go?

答案1

得分: 2

如果尽管你在全局git配置中使用了url."git@github.com:".insteadOf指令,但它仍然使用HTTPS URL,你可能需要尝试使用个人访问令牌(PAT)代替。

就像这个例子中所示,尝试运行以下命令:

git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

(假设你有权限访问该仓库)

然而,考虑到https://github.com/gqrcode本身是404,github.com/KangSpace/gqrcode中声明的github.com/gqrcode/xxx导入可能需要先进行更新。

英文:

If it stills uses an HTTPS URL, despite your global git config url."git@github.com:".insteadOf directive, you might need and try using a PAT (personal access token) instead.

As in this example, try

git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

(Assuming you have access to the repository)

Howver, considering https://github.com/gqrcode itself is 404, the github.com/gqrcode/xxx imports declared in github.com/KangSpace/gqrcode might need to be updated first.

huangapple
  • 本文由 发表于 2022年5月13日 17:42:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/72227500.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定