Golang安装与VScode调试配置

773次阅读
没有评论

## 安装

下载地址:https://golang.google.cn/dl

以windows为例,下载完msi文件后双击安装。然后添加安装目录下的`bin`文件夹到环境变量,一般默认是`C:/Program Files/Go/bin`

测试:

“`bash
go version
>>> go version go1.16.3 windows/amd64
“`

## 为VScode配置Go语言环境

* 在VScode中,安装Go插件
* 打开cmd,设置`GOPROXY`,解决国内连接github容易中断的问题。

“`bash
go env -w GOPROXY=https://goproxy.cn,direct
“`
* **重启**VScode,快捷键`Ctrl+Shift+P`,输入`Go:Install/Update Tools`,全选安装所有插件

## 无法debug?

写一个简单的例子,按F5会报错`Failed to continue: Check the debug console for details.`,然后提示你修改`launch.json`

改就好了

“`json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
“version”: “0.2.0”,

“configurations”: [
{
“name”: “Launch file”,
“type”: “go”,
“request”: “launch”,
“mode”: “auto”,
“program”: “${file}”,
“env”: {
“PATH”: “C:/Program Files/Go/bin:${fileDirname}”
},
“args”: []
}
]
}
“`

只有”env”中的”PATH”才需要修改为你自己的值,其实就是GO程序根目录/bin文件夹地址,可以在cmd中输入`go env`,查看`GOROOT`,并替换掉`/bin`之前的地址。

改完之后可以debug了,但是仍然有大堆红色的提示信息,很难看

“`plaintext
Failed to get state – Process 39852 has exited with status 0
dumpStacktrace – Failed to get debugger state Process 39852 has exited with status 0
dumpStacktrace: Failed to produce stack traceProcess 39852 has exited with status 0
Process exiting with code: 0
“`

解决方案:安装`Go Nightly`插件,再次F5,成功运行!

![image.png](https://i.yanshu.work/image/60673a85958d3.jpg)Read More 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 
评论(没有评论)
Generated by Feedzy