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 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型