使用代理获取私有仓库的方法是:

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

go get PRIVATE repo with proxy

问题

我的公司提供了一个VPN,但只提供了全局代理,所以我在Docker中启动了一个VPN,并向外部提供了socks5代理,我希望能够使用我本地启动的socks5代理来执行go get ≈ <private_repo_path>

我的配置文件

  • Go环境
GOPRIVATE="<company_gitlab_url>"
GOPROXY="http://goproxy.cn,direct"(我在中国,这是中国的Golang代理)
  • Git
[http "https://<company_gitlab_url>"]
    proxy = socks5://127.0.0.1:1080
    
insteadOf = http://<company_gitlab_url>/
insteadOf = http://<company_gitlab_url>/
  • netrc
machine <company_gitlab_url>
  login username
  password accessToken

我期望git clone <company_gitlab>/<repo_name>命令使用socks5代理,所以我为git配置了http代理,它可以正常工作。

[http "https://<company_gitlab_url>"]
    proxy = socks5://127.0.0.1:1080

但是go get <company_gitlab>/<repo_name>不起作用(没有使用socks5代理)。

我知道go get本质上是git clone,而且我已经设置了ssh insteadOf http,所以我认为我应该配置一个SSH代理:

所以我在.ssh/config中添加了以下配置:

Host <company_gitlab_url>
    ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

但是它不起作用。

go get <company_gitlab_url>/<repo_name>显示:

>go get: 无法识别的导入路径"<company_gitlab_url>/golang/base":https获取:获取"https://<company_gitlab_url>/golang/base?go-get=1"时出错:拨号tcp 10.130.xxx.xxx:443:i/o超时

我认为10.130.xxx.xxx是我公司Gitlab.net的内部IP,我该怎么办?

英文:

My company provides a VPN, but only a global proxy, so I started a vpn in docker and provided the sock5 proxy to the outside, and I wanted go get ≈ &lt;private_repo_path&gt; use my locally started sock5 proxy.

my configuration file

- Go env
``` 
GOPRIVATE=&quot;&lt;company_gitlab_url&gt;&quot;
GOPROXY=&quot;http://goproxy.cn,direct&quot; (I&#39;m in China. This is CN Golang Proxy)
```
- Git
```
[http &quot;https://&lt;company_gitlab_url&gt;&quot;]
    proxy = socks5://127.0.0.1:1080
    
insteadOf = http://&lt;company_gitlab_url&gt;/
insteadOf = http://&lt;company_gitlab_url&gt;/ ``` - netrc ``` machine &lt;company_gitlab_url&gt; login username password accessToken ```

I'm expecting the git clone &lt;company_gitlab&gt;/&lt;repo_name&gt; command use the sock5 proxy,so I've configured the http proxy for git, it works

[http &quot;https://&lt;company_gitlab_url&gt;&quot;]
        proxy = socks5://127.0.0.1:1080

But go get &lt;company_gitlab&gt;/&lt;repo_name&gt; not work (not use the sock5 proxy)

Knowing that go get is essentially git clone and that I have ssh insteadOf http set up, I thought I should configure an SSH proxy:

So I added the following configuration to .ssh/config

Host &lt;company_gitlab_url&gt;
    ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

But it doesn't work

go get &lt;company_gitlab_url&gt;/&lt;repo_name&gt; shows

>go get: unrecognized import path "<company_gitlab_url>/golang/base": https fetch: Get "https://<company_gitlab_url>/golang/base?go-get=1": dial tcp 10.130.xxx .xxx:443: i/o timeout

I think 10.130.xxx.xxx is the internal IP of my company Gitlab.net, what should I do?

答案1

得分: 3

我修复了,go get xx 不仅使用 SSH,还有一次 HTTP 获取。

所以使用 https_proxy(http_proxy)=sock5://xxx go get xxx 命令。

英文:

I fix it,go get xx not only use ssh,and has once http fetch。

so use https_proxy(http_proxy)=sock5://xxx go get xxx command

huangapple
  • 本文由 发表于 2022年9月4日 00:41:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/73593896.html
匿名

发表评论

匿名网友

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

确定