1,在VScode找到Go插件
2,在VSCode里的菜单栏里找到"查看"-"调试"-"添加配置",打开一个launch.json文件,将下面的复制进去替换.
注意将 "env": {
"GOPATH":"D:/Develop/vscodegolang"
} 里的GOPATH换成自己的工程路径(包含src,bin的文件夹)
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"GOPATH":"K:/Golang/PaChong"
},
"args": [],
"showLog": true
},
{
"name": "server",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/src/server",
"env": {
"GOPATH":"K:/Golang/PaChong"
},
"args": [],
"showLog": true
}
]
}
3,设置系统的GOPATH.
我的电脑-属性-高级系统设置 -环境变量-GOPATH
如果有多个工程,可以在后面加;再添加另一个工程路径.
4,然后F5运行,F9打断点,F11单步调试