Go配置代理

2023-11-30后端1 分钟203 次阅读
AI 摘要salmon-ai

本文详细解析了如何为 Go 配置代理以加快第三方依赖下载,并介绍了 Go

前言

有时下载个第三方包非常慢甚至下载不了,我们可以使用Goproxy 配置来设置代理。

Go 版本要求

建议使用 Go 1.13 及以上版本。

配置 Goproxy 环境变量

Bash (Linux or macOS)

bash 复制代码
export GOPROXY=https://goproxy.io,direct

PowerShell (Windows)

powershell 复制代码
$env:GOPROXY = "https://goproxy.io,direct"

使配置长久生效 (推荐)

上面的配置步骤只会当次终端内生效,如何长久生效呢,这样就不用每次都去配置环境变量了。

Mac/Linux

bash 复制代码
# 设置你的 bash 环境变量,或者写入~/.bash_profile里
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. 最后点击 “确定” 按钮保存设置

国内常用代理列表

提供方 代理地址
官方全球代理 https://proxy.golang.com.cn/
七牛云 https://goproxy.cn/
阿里云 https://mirrors.aliyun.com/goproxy/
GoCenter https://gocenter.io/
百度 https://oproxy.bj.bcebos.com/
觉得有用就点个赞,不用登录也能读

评论

0 条
登录 之后才能评论
—
还没有评论,来说第一句