Go 国内加速镜像

go的很多包都需要在国外的网站拉取,比如golang.org/x/...。而且在国内拉取github上的模块也很慢,一般推荐一下三个镜像站:

配置Goproxy环境变量

MacOS or Linux

1
2
export GO111MODULE=on
export GOPROXY=https://goproxy.io,direct

Window(PowerShell)

1
2
$env:GO111MODULE = "on"
$env:GOPROXY = "https://goproxy.io,direct"

配置长久生效

Mac or Linux

1
2
3
4
5
# 设置你的 bash 环境变量
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.profile && source ~/.profile

# 如果你的终端是 zsh,使用以下命令
echo "export GOPROXY=https://goproxy.io,direct" >> ~/.zshrc && source ~/.zshrc

Windows

  1. 右键 我的电脑 -> 属性 -> 高级系统设置 -> 环境变量
  2. 在 “[你的用户名]的用户变量” 中点击 ”新建“ 按钮
  3. 在 “变量名” 输入框并新增 “GOPROXY”
  4. 在对应的 “变量值” 输入框中新增 “https://goproxy.io,direct”
  5. 最后点击 “确定” 按钮保存设置