Macvisual studio codegolangdebug

1. brew安装golang

# 安装
brew install golang
# 查看是否安装成功
$ go version
go version go1.12.7 darwin/amd64
$ brew info go
go: stable 1.13.3 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.12.7 (9,816 files, 452.7MB) *
  Poured from bottle on 2019-07-16 at 22:22:49
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.10 ✔
==> Options
--HEAD
    Install HEAD version

2. 配置Golang环境变量

GOROOTGOPATHsrc、bin、pkgvim ~/.bash_profile
export GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
export GOPATH="${HOME}/Documents/go"
export PATH="${PATH}:${GOPATH}:${GOPATH}/bin"
source ~/.bash_profilego env
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxxx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxxx/Documents/work/go_work"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.7/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.7/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4t/rrdtjpp9487_6gf8mclrslpm0000gn/T/go-build714070253=/tmp/go-build -gno-record-gcc-switches -fno-common"

3. 安装vscode

  • 官网下载安装:vscode 官网
  • brew cask 安装:
# 安装:
brew cask install visual-studio-code
# 查看 vscode 信息:
-> % brew cask info visual-studio-code
visual-studio-code: 1.3.1,e6b4afa53e9c0f54edef1673de9001e9f0f547ae
Microsoft Visual Studio Code, VS Code
https://code.visualstudio.com/
Not installed
https://github.com/caskroom/homebrew-cask/blob/master/Casks/visual-studio-code.rb
==> Contents
  Visual Studio Code.app (app)
  /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code (binary)
{
 "files.autoSave": "afterDelay",
 "editor.fontSize": 14,    // 以像素为单位控制字号。
 "terminal.external.osxExec": "iterm.app", // 自定义要在 OS X 上运行的终端应用程序
 "go.gopath": "/Users/xxxx/", // 个人的 GOPATH个人开发工作区
 "go.goroot": "/usr/local/Cellar/go/1.7.3/libexec", //GO安装目录
 "workbench.statusBar.visible": false
}

4. 使用 vscode 自动安装 debug 必备的插件

由于网络原因可能无法下载(无法上外网)的解决方案:

git clone https://github.com/golang/tools.git tools
cp -r $GOPATH/src/github.com/golang/tools $GOPATH/src/golang.org/x/
Updating Homebrew...
Error: No available formula with the name "go-delve/delve/delve"
==> Searching for a previously deleted formula (in the last month)...
Warning: go-delve/delve is shallow clone. To get complete history run:
 git -C "$(brew --repo go-delve/delve)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
xcode-select --install
cd $GOPATH/src/github.com/derekparker
git clone https://github.com/derekparker/delve.git
cd delve
# 安装
CERT=dlv make install

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-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 golang.org/x/tools/cmd/guru