1. Vs Code报错如下:

Tools environment: GOPATH=C:\Users\***\go

Installing 10 tools at C:\Users\***\go\bin in module mode.

gopkgs

go-outline

gotests

gomodifytags

impl

goplay

dlv

dlv-dap

staticcheck

gopls


{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v github.com/uudashr/gopkgs/v2/cmd/gopkgs",

"stdout": "",

"stderr": "go get: module github.com/uudashr/gopkgs/v2/cmd/gopkgs: Get \"https://proxy.golang.org/github.com/uudashr/gopkgs/v2/cmd/gopkgs/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v ramya-rao-a/go-outline",

"stdout": "",

"stderr": "go get: module github.com/ramya-rao-a/go-outline: Get \"https://proxy.golang.org/github.com/ramya-rao-a/go-outline/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v github.com/cweill/gotests/gotests",

"stdout": "",

"stderr": "go get: module github.com/cweill/gotests/gotests: Get \"https://proxy.golang.org/github.com/cweill/gotests/gotests/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v fatih/gomodifytags",

"stdout": "",

"stderr": "go get: module github.com/fatih/gomodifytags: Get \"https://proxy.golang.org/github.com/fatih/gomodifytags/@v/list\": dial tcp 172.217.160.81: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v josharian/impl",

"stdout": "",

"stderr": "go get: module github.com/josharian/impl: Get \"https://proxy.golang.org/github.com/josharian/impl/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v github.com/haya14busa/goplay/cmd/goplay",

"stdout": "",

"stderr": "go get: module github.com/haya14busa/goplay/cmd/goplay: Get \"https://proxy.golang.org/github.com/haya14busa/goplay/cmd/goplay/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v github.com/go-delve/delve/cmd/dlv",

"stdout": "",

"stderr": "go get: module github.com/go-delve/delve/cmd/dlv: Get \"https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v -d github.com/go-delve/delve/cmd/dlv@master",

"stdout": "",

"stderr": "go get: github.com/go-delve/delve/cmd/dlv@master: invalid version: Get \"https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/master.info\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v honnef.co/go/tools/cmd/staticcheck",

"stdout": "",

"stderr": "go get: module honnef.co/go/tools/cmd/staticcheck: Get \"https://proxy.golang.org/honnef.co/go/tools/cmd/staticcheck/@v/list\": dial tcp 172.217.160.113: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.\n"

}

{

"killed": false,

"code": 1,

"signal": null,

"cmd": "E:\\Go_Install\\bin\\go.exe get -v golang.org/x/tools/gopls",

"stdout": "",

"stderr": "go get: module golang.org/x/tools/gopls: Get \"https://proxy.golang.org/golang.org/x/tools/gopls/@v/list\": dial tcp 172.217.160.113: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.\n"

}

2.原因

国内FHQ政策,以及Vs Code 中go的第三方扩展库地址不对。


3.解决办法。

以windows为例,

在cmd 窗口中执行下列语句

go env -w GO111MODULE=on

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

如果报go找不到,编辑下Path,或者从官方网站下载golang安装。


然后,在cmd中手动下载第三方扩展库。下载命令如下:

对照以上命令行,替换vs code中报错的那几个包安装。


4.尝试第一个helloworld程序。

在GOPATH下创建helloworld.go程序。GOPATH地址用go env获得。


VSCode---文件---打开文件夹,选择GOPATH目录。建立helloworld.go文件。

内容如下:

package main

import "fmt"

func main() {
fmt.Printf("hello world.")
}
保存重启VsCode,一定要重启VsCode。

左边是调试按钮,右边是控制台输出信息。

成功。