Go—GOPROXY代理 invalid $GOPROXY setting error

Go 由于是谷歌研发出品,很多开源依赖包都在国外服务器,down包经常会出现当不下来的情况,此时就需要设置$GOPROXY 代理,通过国内代理链接来获取包资源。

常用代理路径:https://goproxy.io/

网站打开很直白的介绍了如何设置$GOPROXY变量。

In Linux or macOS, you can execute the below commands.
Bash /
# Enable the go modules feature
export GO111MODULE=on
# Set the GOPROXY environment variable
export GOPROXY=https://goproxy.io
Or, write it into the .bashrc or .bash_profile file.
In Windows, you can execute the below commands.
PowerShell 
# Enable the go modules feature
$env:GO111MODULE=on
# Set the GOPROXY environment variable
$env:GOPROXY=https://goproxy.io
Now, when you build and run your applications, go will fetch dependencies via goproxy.io. See more information in the goproxy repository.
If your Go version >= 1.13, the GOPRIVATE environment variable controls which modules the go command considers to be private (not available publicly) and should therefore not use the proxy or checksum database. For example:
Go version >= 1.13
go env -w GOPROXY=https://goproxy.io,direct
# Set environment variable allow bypassing the proxy for selected modules
go env -w GOPRIVATE=*.corp.example.com

简单操作一番

Go—GOPROXY代理 invalid $GOPROXY setting error_第1张图片

注:首先在通过go get 获取包时,报invalid $GOPROXY setting error,通过分析报错信息,并输出$GOPROXY可见是我的代理链接没对,根据ttps://goproxy.io/中guide执行export后,再go get package方可正常下载资源。最后直接在程序中import包即可使用。

import (
   "github.com/jinzhu/gorm"
   _ "github.com/jinzhu/gorm/dialects/sqlite"
)

另外一篇关于go 代理设置的博客,推荐给大家。【Go第三方包代理】Go第三方包代理设置 — GOPROXY

你可能感兴趣的:(【Go】)