Mac OS 安装 VS Code + Golang 调试工具

①gopath系统环境变量,在~/.bash_profile文件中添加:
这个设置以后,系统默认的go环境就指定好了,如果不重新指定,则默认识别的都是这里设置的(包括代码提示引用的路径、三方包go get安装的路径)。常用于统一存放第三方包和安装的bin插件。

GOPATH=”/Users/lee/Documents/global”
export GOPATH
export PATH=$GOPATH:$PATH
export PATH=$GOPATH/bin:$PATH

②vscode>“用户设置”,第三方包依赖的插件路径
由于vscode支持为每个项目单独设置环境:“工作区设置”。为了避免每个工作区重复下载依赖的插件,可以手动指定插件统一依赖于系统环境指定的GOPATH(我们安装的包默认也是放在这里的),参考①。

“go.toolsGopath”:”/Users/lee/Documents/global”

③vscode>打开项目的“工作区设置”,为每个项目设置单独的gopath:
“go.gopath”: “/Users/shuai/Documents/project_a”

④安装vscode的插件。
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
https_proxy=http://127.0.0.1:1087 go get -u -v github.com/golang/lint/golint
go get -u -v github.com/lukehoban/go-outline
https_proxy=http://127.0.0.1:1087 go get -u -v sourcegraph.com/sqs/goreturns
https_proxy=http://127.0.0.1:1087 go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs
https_proxy=http://127.0.0.1:1087 go get -u -v github.com/newhook/go-symbols
https_proxy=http://127.0.0.1:1087 go get -u -v github.com/cweill/gotests/…
https_proxy=http://127.0.0.1:1087 go get -u -v golang.org/x/tools/cmd/guru

https_proxy=http://127.0.0.1:1087 go get -u -v github.com/go-swagger/go-swagger/cmd/swagger

https_proxy=http://127.0.0.1:1087 go get -u -v github.com/micro/micro
https_proxy=http://127.0.0.1:1087 go get -u -v github.com/micro/kubernetes/cmd/micro

https_proxy=http://127.0.0.1:1087 go get -u -v github.com/jinzhu/gorm

https_proxy=http://127.0.0.1:1087 go get -u -v github.com/golang/protobuf/{proto,protoc-gen-go}
https_proxy=http://127.0.0.1:1087 go get -u -v google.golang.org/grpc
https_proxy=http://127.0.0.1:1087 go get -u -v github.com/micro/protoc-gen-micro

//如果需要在vscode中调试go程序,需要下载安装dlv
go get -u -v github.com/derekparker/delve/cmd/dlv

报错
could not launch process: exec: “lldb-server”: executable file not found in $PATH
解决方法
xcode-select –install

报错
dlv could not launch process: EOF
解决方法
sudo rm -rf /Library/Developer/CommandLineTools
then go to page https://developer.apple.com/download/more/
download and install previous version
Command Line Tools (macOS 10.13) for Xcode 9.2 2018.4.8

launch.json
“program”: “${workspaceRoot}/src/test.go”,