vscode 配置go环境 可调试

xiaoxiao2021-02-27  353

1、go下载安装并配置环境变量

2、安装工具:

1)安装gocode

go get -u -v github.com/nsf/gocode

2)安装godef

go get -u -v github.com/rogpeppe/godef

3)安装golint

go get -u -v github.com/golang/lint/golint

4)安装go-find-references

go get -u -v github.com/lukehoban/go-find-references

5)安装go-outline

go get -u -v github.com/lukehoban/go-outline

6)安装goreturns

go get -u -v sourcegraph.com/sqs/goreturns

7)安装gorename

go get -u -v golang.org/x/tools/cmd/gorename

3Visual Studio Code支持Go语言调试 执行以下命令:

go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv brew install go-delve/delve/delve go get -v -u github.com/peterh/liner github.com/derekparker/delve/cmd/dlv 修改“dlv-cert”证书

1.打开“钥匙串访问” 2.打开菜单->钥匙串访问->证书助理->创建证书 3.名称:dIv 身份类型:自签名证书 证书类型:代码签名 并选择“让我覆盖这些默认值” 4.单击“继续”,有限期(天数):365,可以自己修改,3650 5.一直继续,直到看到“指定用于该证书的位置”钥匙串,选择“系统”并单击“创建”按钮 6.重启Finder,再打开“钥匙串访问”,选择“系统”,就会看到创建好的“dlv-cert”证书 7.右键"dlv-cert"证书,选择“显示简介->信任->代码签名”修改为:始终信任 8.打开terminal,进入到之前安装好的$GOPATH/src目录下的dlv源码文件目录:github.com/derekparker/delve 9.输入如下命令就可以重新编译出一个带代码签名的dlv执行程序

GO15VENDOREXPERIMENT=1 CERT=dlv-cert make install

可能会遇到的问题

The execution file "./dlv -h" always return >> killed:9

stackoverflow解决方式:

I need to do this step below brew install go-delve/delve/delve and go to $GOPATH/src/github.com/derekparker git clone https://github.com/derekparker/delve.git CERT=dlv-cert make install (remove old dlv > brew install delve > codesign dlv) not just run go get github.com/derekparker/delve/cmd/dlv and it works now.

重启Visual Studio Code,就可以完美使用了。

转载请注明原文地址: https://www.6miu.com/read-3336.html

最新回复(0)