Go directly to the solution:
- One line command to install delve:
go get -u github.com/go-delve/delve/cmd/dlv
(delve is a debugging tool for go language) - Then configure as shown below:
My own launch.json (modify to your own path):
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
//"port": 2345,
//"host": "127.0.0.1",
"program": "/home/daji/data/codes/go_programming/src/daji-HelloGo/test.go",
"env": {
"GOPATH":"/home/daji/data/codes/go_programming"
},
"args": [],
"showLog": true
}
]
}
Finally, click on the position shown in the figure below, and you can run it.