关于golang1.13版本国内代理无法使用问题

         golang1.13发布后 我们go get 一些资源的时候就不用通过特殊方式来下载了,官方提供了代理资源,

但是按照操作一波下来后发现出现以下问题:

go get -u github.com/mdempsky/gocode
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?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 get -u github.com/mdempsky/gocode
package golang.org/x/tools/go/gcexportdata: unrecognized import path "golang.org/x/tools/go/gcexportdata" (https fetch: Get https://golang.org/x/tools/go/gcexportdata?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 GOPROXY=direct
go env -w GOSUMDB=off

设置后并没有效果,其实仔细看下文档

The GOPROXY environment variable may now be set to a comma-separated list of proxy URLs or the special token direct, and its default value is now https://proxy.golang.org,direct. When resolving a package path to its containing module, the go command will try all candidate module paths on each proxy in the list in succession. An unreachable proxy or HTTP status code other than 404 or 410 terminates the search without consulting the remaining proxies.

说是需要 https://proxy.golang.org,direct 这个地址 

那么我们改成这样:

go env -w GOPROXY=https://goproxy.io,direct

再次去go get 资源 还是无法代理加载

这个时候我们 go env 看下是否设置好

go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=***
set GOENV=*************
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=*.corp.example.com
set GONOSUMDB=*.corp.example.com
set GOOS=windows
set GOPATH=************
set GOPRIVATE=*.corp.example.com
set GOPROXY=https://goproxy.cn,direct
set GOROOT=*******
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=*******
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=********

GOPROXY 其实已经是我们设置的代理了(*号根据自己目录请勿参考),

然后我们发现 第一个 GO111MODULE 是空的 那么问题找到了

我们只需要打开它

go env -w GO111MODULE="on"

然后再去加载资源

go get -u github.com/mdempsky/gocode
go: finding github.com/mdempsky/gocode latest
go: downloading github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f
go: extracting github.com/mdempsky/gocode v0.0.0-20190203001940-7fb65232883f
go: finding golang.org/x/tools latest
go: downloading golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110
go: extracting golang.org/x/tools v0.0.0-20190911022129-16c5e0f7d110

已经代理成功!!!!!!!

    希望可以帮到大家,如有问题多多指教!!! 

发布了15 篇原创文章 · 获赞 13 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_36546907/article/details/100732841