Plan A: 使用 go remote debug 远程机器的 go 程序
安装 go 环境
1 | go version go1.21.2 linux/amd64 |
切换代理
1 | $ go env -w GOPROXY=https://goproxy.cn,direct |
安装 dlv
1 | $ go install github.com/go-delve/delve/cmd/dlv@latest |
迁移 dlv 命令到 /usr/bin
1 | $ cp $GOPATH/bin/dlv /usr/bin |
使用 dlv 运行 go 程序
1 | nohup sudo dlv --listen=:2345 --headless=true --api-version=2 exec ./ogcli server & |
使用 goland go remote 绑定端口 debug
Plan B: 使用 go build ssh 部署到远程机器
go build 选择 ssh 并配置节点信息
TODO:图片补充
更新:经测试 GoLand 24.1.4 不需要额外配置和切换 dlv 即可 debug
修改 idea.properties (需要重启 goland)
1 | #dlv.path=C:\\Users\\Rosin\\go\\bin\\dlv.exe |
修改启动报错
原因:goland 远程部署 debug 时是用的本地 dlv 环境
https://youtrack.jetbrains.com/issue/GO-10971/Remote-debugging-dlv-syntax-error#focus=Comments-27-4852093.0-0
缺点:需要修改 dlv 路径,影响本地部署测试