Golang安装依赖包终极打发:GOPROXY环境变量

我们知道从 Go 1.11 版本开始,官方支持了 go module 包依赖管理工具。

其实不仅如此, Go 1.11 还新增了 GOPROXY 环境变量。如果设置了该变量,下载源代码时将会通过这个环境变量设置的代理地址。

更可喜的是,goproxy.io 提供了一个开源的解决方案允许开发者一键构建自己的 GOPROXY 代理服务。同时,也提供了公用的代理服务 https://goproxy.io,而七牛云也出了个国内代理 goproxy.cn 方便国内用户更快的访问。

最终的使用效果如下:

使用前:

$ go get -u -v golang.org/x/tools/go/packages
package golang.org/x/tools/go/packages: unrecognized import path "golang.org/x/tools/go/packages" (https fetch: Get https://golang.org/x/tools/go/packages?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

使用后:

$ go env -w GO111MODULE=on
            
$ go env -w GOPROXY=https://goproxy.cn,direct
warning: go env -w GOPROXY=... does not override conflicting OS environment variable

$ go get -u -v github.com/securego/gosec/cmd/gosec
go: finding github.com/securego/gosec latest
go: downloading github.com/securego/gosec v0.0.0-20191217083152-cb4f343eaff1
go: extracting github.com/securego/gosec v0.0.0-20191217083152-cb4f343eaff1
go: downloading gopkg.in/yaml.v2 v2.2.7
go: extracting gopkg.in/yaml.v2 v2.2.7
go: finding gopkg.in/yaml.v2 v2.2.7
go: finding golang.org/x/tools latest
go: finding github.com/nbutton23/zxcvbn-go latest
github.com/nbutton23/zxcvbn-go/match
github.com/nbutton23/zxcvbn-go/utils/math
gopkg.in/yaml.v2
github.com/securego/gosec
github.com/nbutton23/zxcvbn-go/data
github.com/nbutton23/zxcvbn-go/frequency
github.com/nbutton23/zxcvbn-go/adjacency
github.com/nbutton23/zxcvbn-go/entropy
github.com/securego/gosec/output
github.com/nbutton23/zxcvbn-go/scoring
github.com/nbutton23/zxcvbn-go/matching
github.com/nbutton23/zxcvbn-go
github.com/securego/gosec/rules
github.com/securego/gosec/cmd/gosec            
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值