关于Go Module拉取私有仓库时,遇到terminal prompts disabled权限的问题。go get 包代理设置

访问github 私有仓库设置

前提 ssh秘钥已配好

现象

fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.

[root@vm10-10-128-68 mywarning]# go get github.com/zhangmingda3/ksyunwarning@0795e78e88bf71a84968d3b5a491f79e3727a6eb
go: github.com/zhangmingda3/ksyunwarning@0795e78e88bf71a84968d3b5a491f79e3727a6eb: invalid version: git ls-remote -q origin in /root/go/pkg/mod/cache/vcs/3b597a61692748d78723c42315f9aace7226099be1a17d10da0a21a735d16ad0: exit status 128:
    fatal: could not read Username for 'https://github.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.
[root@vm10-10-128-68 mywarning]#

设置GIT_TERMINAL_PROMPT

go get源码包中有以下一段代码:

90     // Disable any prompting for passwords by Git.
91     // Only has an effect for 2.3.0 or later, but avoiding
92     // the prompt in earlier versions is just too hard.
93     // If user has explicitly set GIT_TERMINAL_PROMPT=1, keep
94     // prompting.
95     // See golang.org/issue/9341 and golang.org/issue/12706.
96     if os.Getenv("GIT_TERMINAL_PROMPT") == "" {
97          os.Setenv("GIT_TERMINAL_PROMPT", "0")
98     }

可以通过设置环境变量GIT_TERMINAL_PROMPT = 1 来开启账号密码的验证。

https替换成ssh

需要在仓库绑定SSH公钥

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

配置后查看git config

[root@vm10-10-128-68 mywarning]# git config --list
user.name=zhangmingda3
user.email=zhangmingda666888@163.com
url.git@github.com:.insteadof=https://github.com/

配置仓库的全局选项将https替代成ssh

设置 GOPRIVATE

通过GOPRIVATE来指定你的仓库

go env -w GOPRIVATE=xxx.com/xxx

再次 go get 

 

goLand 访问github.com 下载包超时 

connectex: A connection attempt failed because the connected party did not properly respond af
ter a period of time, or established connection failed because connected host has failed to respond.

 

 配置代理 

go env -w GOPROXY=https://goproxy.cn,direct 

再次下载成功

 

posted on 2023-02-28 18:55  zhangmingda  阅读(5820)  评论(0)    收藏  举报

导航