- go 源代码
//调试
json
{
"name": "Debug ***",
"type": "go",
"request": "launch",
"mode": "debug", // 调试模式(自动检测或指定)
"program": "${workspaceFolder}/apps/eapd/main.go", // 可执行文件路径
"args": [ // 命令行参数(需拆分为数组元素)
"-service-hostname=127.0.0.1",
"-port=9502",
"-etcd-endpoints=http://127.0.0.1:9597",
"-etcd-user=***",
"-etcd-password=*****",
"-database-driver=PostgreSQL Unicode(x64)",
"-affinity-label=",
"-anti-affinity-label=",
"-redirect-stderr=yes",
"--debug=yes"
],
"env": {}, // 如需环境变量,可在此添加(如 ETCD 配置可能依赖环境变量)
"cwd": "${workspaceFolder}", // 工作目录
"buildFlags": "", // 编译选项(如需要优化或调试符号)
"showLog": true // 显示调试日志(可选)
}
- go 二进制
//前提:带调试信息
cmd
go build -gcflags="-N -l" -o D:/path/to/**.exe
//调试二进制
json
{
"name": "Debug ** (Binary)",
"type": "go",
"request": "launch",
"mode": "exec", // 指定调试已编译的二进制
"program": "${workspaceFolder}/bin/**.exe", // 绝对路径(注意转义)
"args": [ // 命令行参数(拆分为数组元素)
"-service-hostname=127.0.0.1",
"-port=9502",
"-etcd-endpoints=http://127.0.0.1:9597",
"-etcd-user=caxaplm",
"-etcd-password=***",
"-database-driver=PostgreSQL Unicode(x64)",
"-affinity-label=",
"-anti-affinity-label=",
"-redirect-stderr=yes",
"--debug=yes"
],
"cwd": "${workspaceFolder}",
"dlvFlags": ["--check-go-version=false"], // 忽略版本检查(可选)
"buildFlags": "" // 无需编译,直接调试
}
- 附加
//前提:带调试信息
cmd
go build -gcflags="-N -l" -o D:/path/to/**.exe
json
{
"name": "Attach to Process",
"type": "go",
"request": "attach",
"mode": "local",
"processId": "${command:pickProcess}", //弹出进程搜索框
},