Goland如何实现远程开发调试

    学习Go语言过程中,特别是看各种开源框架时候免不了要进行debug。不习惯本地debug的小伙伴,会想怎么远程debug呢?别急,这就给你端上来怎么用Goland实现远程开发调试。

依赖工具

1.Goland,请自行下载且解决破解码问题,百度一大把
2.Linux开发环境,且安装go,参考:Go部署安装和配置 - (jianshu.com)
3.dlv, - 写文章 (jianshu.com)

远程调试配置

1.SFTP远程代码同步
    Goland 添加SFTP: Goland菜单: tools – deployment - configure 点击 ➕  SFTP,
    ![image.png](https://upload-images.jianshu.io/upload_images/3094696-39325bb3a342e3a3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

Goland SFTP 本地代码目录映射


image.png

勾选自动上传Goland菜单: Tools -> Deployment -> Auto Upload(Always)

2.Goland的Debug配置
    Goland配置go remote:Goland菜单:run - edit Configurations 点击 ➕  GO Remote
    ![image.png](https://upload-images.jianshu.io/upload_images/3094696-1427f4db36c24932.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
3.服务器开启dlv服务
    3.1 用cd 到代码目录,然后编译go build 得到可执行文件。
    ```
    cd $GOPAHT/src
    make
    ````
  3.2 服务器开启dlv服务
    ![image.png](https://upload-images.jianshu.io/upload_images/3094696-cea2a1c9c64d597b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Goland开始Debug
       Goland找到瓢虫按钮,开始debug模式。
     ![image.png](https://upload-images.jianshu.io/upload_images/3094696-baf6dab88b9b5ee9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
      然后加断点,开玩咯。

你可能感兴趣的:(Goland如何实现远程开发调试)