1. GOPROXY环境变量作用:
①. 不再从以前的直接从代码库下载.
②. 使用环境变量设置的代理地址下载源代码.
(1). 查看:
$ go env
...
GOPROXY="https://goproxy.io,direct"
2. Go version >= 1.13(RECOMMENDED):
go env -w GO111MODULE=on
go env -w GOPROXY="https://goproxy.io,direct"
# 加速设置
# Set environment variable allow bypassing the proxy for selected modules(optional)
# 设置不走proxy的私有仓库,多个用逗号相隔(可选)
go env -w GOPRIVATE="*.corp.example.com"
注:
Now,when you build your applications,Go will fetch dependencies via goproxy.io.
设置完上面几个环境变量后,您的go命令将从公共代理镜像中快速拉取您所需的依赖代码了.
3. Go version <= 1.12:
(1). Bash (Linux or macOS):
# Enable the go modules feature(启用Go Modules功能):
echo $GO111MODULE
export GO111MODULE="on" // 默认是auto,当项目下有go.mod文件时,会使用go module机制
# Set the GOPROXY environment variable(配置GOPROXY环境变量):
export GOPROXY="https://goproxy.io"
注:
Or, write it into the .profile or .bash_profile file.
或者,将它写到.profile或.bash_profile文件中长期生效.
(2). PowerShell (Windows):
# Enable the go modules feature:
echo %GO111MODULE%
env:GO111MODULE="on"
# Set the GOPROXY environment variable:
env:GOPROXY="https://goproxy.io"
注:
Now, when you build your applications, Go will fetch dependencies via goproxy.io.
现在,当你构建或运行你的应用时,Go将会通过goproxy.io获取依赖.
`