Skip to content

go debug

go install github.com/go-delve/delve/cmd/dlv@latest

vim .vscode/launch.json

json
{
  // 使用 IntelliSense 了解相关属性。
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Gin",
      "type": "go",
      "request": "launch",
      "mode": "auto",
      "program": "${workspaceFolder}/cmd/server/main.go"
    }
  ]
}

有时候断点跳不过去,是因为优化。

configurations 中添加

json
"buildFlags": "-gcflags=all=-N -l"