在VS Code中配置GO开发环境并调试
1.安装Go 和VScode,
2.配置环境变量GOPATH
确保go root 和go path在系统变量path里面
3.VScode设置goroot 和gopath
下载一些必要的包
由于网络原因请设置代理
go env -w GO111MODULE=on go env -w GOPROXY=https://goproxy.cn,direct
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -u -v github.com/zmb3/gogetdoc
go get -u -v github.com/cweill/gotests
go get -u -v github.com/derekparker/delve/cmd/dlv
go get -u -v golang.org/x/tools/cmd/guru
go get -u -v github.com/fatih/gomodifytags
go get -u -v github.com/haya14busa/goplay/cmd/goplay
go get -u -v github.com/josharian/impl
go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
go get -u -v golang.org/x/tools/cmd/godoc
go get -u -v golang.org/x/tools/cmd/goimports
生成运行配置文件
运行调试效果图
多项目我一般推荐附加进程,首先在vscode 里面启动里的程序, 比如我的是beego项目【bee run】,然后添加修改配置文件
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Attach to Process", "type": "go", "request": "attach", "mode": "local", "processId": 10984 }, ] }
其中10984是进程ID
调试效果图: