远程调试 Go REST 端点

Remote Debugging Go REST Endpoints

我是 Go 的新手,也是 VSCode 的新手。我以前也从未使用过 Delve。我正在尝试设置远程调试,但我似乎无法设置断点。

我的项目在 localhost:8080 上托管 REST 端点。 launch.json 文件应该是什么样子才能让 delve 附加和侦听,以便我可以在我的 REST 端点上放置断点?目前,这就是我所拥有的:

"configurations": [
    {
        "name": "Launch",
        "type": "go",
        "request": "launch",
        "mode": "remote",
        "remotePath": "",
        "port": 8080,
        "host": "127.0.0.1",
        "program": "${workspaceRoot}",
        "env": {},
        "args": [],
        "showLog": true
    }

提前致谢!

This article提到:

不幸的是,当 运行 buffalo dev 时,您将无法调试应用程序。您需要构建一个可跳过编译器优化(如函数调用内联)的可执行文件。
如果您跳过这些构建标志,Gogland 将不会在您的断点处停止

有关“Debugging Go Code with GDB ”的更多信息。

The code generated by the gc compiler includes inlining of function invocations and registerization of variables. These optimizations can sometimes make debugging with gdb harder.

之后可以关注“Remote Debugging

To remote debug using VS Code, you must first run a headless Delve server on the target machine. For example:

$ dlv debug --headless --listen=:2345 --log

然后你的启动器就可以应用了。