19 มิถุนายน 2561

debugging golang using visual studio code (vscode)

To debug golang using vscode is quite easy. There are just 2 steps to do it.

1. download delve (go debugger) from https://github.com/derekparker/delve and follow the step to install it, e.g., for Mac OSX user, just run

go get -u github.com/derekparker/delve/cmd/dlv


2. setup launch.json in vscode like this

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Go debug",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"cwd": "${workspaceRoot}",
"showLog": true
}
]
}

3. create main.go, and try to debug it

If you see error "econnrefused 127.0.0.1:2345", try remove host and port

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Go debug",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"cwd": "${workspaceRoot}",
"showLog": true
}
]
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (1 ปีย้อนหลัง)