doutao5499 2018-06-19 15:16
浏览 937
已采纳

使用Go和GoLand IDE进行远程调试HTTP请求

I am new to go, delve and GoLand IDE. I would like to remote debug some REST endpoints that are deployed using make and run in a docker (using docker + docker-compose).

The command I use to bring up my environment is make myproject

My endpoints get hosted at: localhost:8080

When creating a debug configuration in GoLand it specifies that before running dlv debug --headless --listen=:2345 --api-version 2, do the following:

go build -gcflags='-N -l' github.com/myproject
dlv --listen=:2345 --headless=true --api version=2 exec ./myproject

Is there a way for me to attach to my project once it's running on localhost:8080? How will these commands differ if that is the case?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • duanniubeng2265 2018-06-19 15:41
    关注

    This command dlv debug --headless --listen=:2345 --api-version 2 your/package/name allows delve to compile the package then launch itself and the compiled binary.

    On the other hand, these commands go build -gcflags='-N -l' github.com/myproject dlv --listen=:2345 --headless=true --api version=2 exec ./myproject show you that you can compile the binary separately, in case you need more flexibility and then launch the debugger. Keep in mind that it's really important to add -gcflags='-N -l' or -gcflags='all=-N -l', depending on which Go version you have, in order for the debugger to be able to have more data available about your application.

    As for the:

    Is there a way for me to attach to my project once it's running on localhost:8080? How will these commands differ if that is the case?

    It depends on where you are running the process. If it's on your machine directly, without a VM or a container, then the IDE has the option in Run|Attach to Process. If the process is running on a different machine then you need to login into that machine and use dlv --headless --listen=:2345 --api-version 2 attach <pid>.

    We published an article dedicated to this problem a couple of months ago, please have a look at it for a more detailed reply.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置