在终端中执行
export https_proxy=http://127.0.0.1:2081
export http_proxy=http://127.0.0.1:2081
git config --global http.proxy 'http://127.0.0.1:2081'
git config --global https.proxy 'http://127.0.0.1:2081'
前提是你拥有一个本地的http proxy,比如v2ray(http proxy mode)。
----------------------------------------------------
------------------------------------------------------
https://goproxy.io/zh/ , https://github.com/goproxyio/goproxy
https://github.com/goproxy/goproxy.cn/blob/master/README.zh-CN.md
export https_proxy=http://127.0.0.1:2081
export http_proxy=http://127.0.0.1:2081
git config --global http.proxy 'http://127.0.0.1:2081'
git config --global https.proxy 'http://127.0.0.1:2081'
前提是你拥有一个本地的http proxy,比如v2ray(http proxy mode)。
----------------------------------------------------
替终端配置代理,解决 go get 命令在国内无法使用的问题
(注:Golang 从
1.13开始默认使用Go Mod,请切换至Go Mod)
问题描述
国内使用go get命令时,Google 相关的域名例如golang.org经常被墙。
方法 1:使用 Gopm
注:Gopm 目前已停止维护
使用gopm get命令替代go get:
> go get -u github.com/gpmgo/gopm
> gopm
NAME:
Gopm - Go Package Manager
USAGE:
Gopm [global options] command [command options] [arguments...]
VERSION:
0.8.8.0307 Beta
COMMANDS:
list list all dependencies of current project
gen generate a gopmfile for current Go project
get fetch remote package(s) and dependencies
bin download and link dependencies and build binary
config configure gopm settings
run link dependencies and go run
test link dependencies and go test
build link dependencies and go build
install link dependencies and go install
clean clean all temporary files
update check and update gopm resources including itself
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--noterm, -n disable color output
--strict, -s strict mode
--debug, -d debug mode
--help, -h show help
--version, -v print the version
配置终端代理:
阅读get.go源码会发现,go get命令通过git clone命令将远程仓库的代码拉取到本地。
根据官方 golang/go - GoGetProxyConfig | Github 的说明,需要设置git的代理:
然而并没有起作用。。
我在Linux和Windows的机器上都开启了Shadowsocks代理,本地端口为1080
搜索了一圈之后发现,需要设置http_proxy和https_proxy这两个环境变量。
for Linux
我在CentOS 7.5的机器上已经使用ProxyChains-NG作为终端命令的代理程序,这样可以很方便的在需要代理的时候在命令前加上pc前缀(之前设置了alias pc='proxychains4')。
而添加http_proxy环境变量后,所有终端命令的 HTTP 连接都会走代理,这并非我所期望的。因此不能直接在~/.zshrc中添加环境变量。
我的解决方案是:将设置http_proxy与https_proxy环境变量的export命令单独写在 Shell 脚本中,需要走代理时直接source即可。
首先以下内容另存为export-http-proxy.sh:
之后添加执行权限
最后
这样就可以直接go get被墙的包了。
for Windows
Windows 就非常简单了,直接设置以下环境变量:
要想临时添加代理,只需将以下内容保存为http-proxy.bat,需要时执行即可:
参考文章:
https://goproxy.io/zh/ , https://github.com/goproxyio/goproxy
https://github.com/goproxy/goproxy.cn/blob/master/README.zh-CN.md
https://github.com/gomods/athens ,A Go module datastore and proxy. docs.gomods.io
No comments:
Post a Comment