参考文章:https://marksuper.xyz/2021/06/29/dlv-goland/
首先安装一下dlv这个工具:
git clone GitHub - go-delve/delve: Delve is a debugger for the Go programming language.
cd delve
go install github.com/go-delve/delve/cmd/dlv

我们直接开始配合goland进行debug。
打开debug配置:


打开项目根目录,使用命令编译并启动dlv:
go1.18 build -o main -gcflags "all=-N -l" && dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./main
命令中的第一个main是go文件的名字,第二个main是编译出来的文件的名字,不加后缀。
执行没问题的话会有以下结果:

这些我们可以回到goland编辑器开启debug了:

之后就可以连上dlv的debug了:



我的这个框架是grpc,也有http的请求。
我们用postman请求一下接口,就可以debug了:

这篇文章就到这里啦!如果你对文章内容有疑问或想要深入讨论,欢迎在评论区留言,我会尽力回答。同时,如果你觉得这篇文章对你有帮助,不妨点个赞并分享给其他同学,让更多人受益。
想要了解更多相关知识,可以查看我以往的文章,其中有许多精彩内容。记得关注我,获取及时更新,我们可以一起学习、讨论技术,共同进步。
感谢你的阅读与支持,期待在未来的文章中与你再次相遇!