自行安装dlv

安装
There are two ways to install on Linux. First is the standard go get method:

go get -u github.com/go-delve/delve/cmd/dlv

Alternatively make sure $GOPATH is set (e.g. as ~/.go) and:

$ git clone https://github.com/go-delve/delve.git $GOPATH/src/github.com/go-delve/delve
$ cd $GOPATH/src/github.com/go-delve/delve
$ make install

dlv启动的三种模式

attach

-gcflags "all=-N -l"
go build -gcflags "all=-N -l" -o juejin main.go  # 编译
./juejin  # 运行
dlv attach 19507 --headless=true --listen=:8080 --api-version=2 --accept-multiclient --log   # attach

exec

exec为手动编译并执行调试的方式

go build -gcflags "all=-N -l" -o juejin main.go  # 编译
dlv --listen=:8080 --headless=true --api-version=2 exec juejin

debug

debug模式自动编译并运行调试

dlv debug --headless --listen=:8080 --api-version=2 main.go

goland连接远程dlv

通过goland的菜单栏Run–>Edit Configurations来添加远程调试的配置
在这里插入图片描述
另外,请使用goland2019.1及更新的版本~