本篇介绍Mac
平台 使用visual studio code
搭建golang
开发环境以及debug
环境的配置git
# 安装 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
GOROOT
: 安装目录GOPATH
: 工做空间目录 (该目录不能和Go的安装目录同样,这个目录下面有三个子目录: src、bin、pkg
)
Mac环境的环境变量设置在vim ~/.bash_profile
,在文件尾部添加github
export GOROOT="/usr/local/Cellar/go/1.12.7/libexec" export GOPATH="${HOME}/Documents/go" export PATH="${PATH}:${GOPATH}:${GOPATH}/bin"
设置完成后 执行source ~/.bash_profile
生效
查看go env
检查环境变量是否设置成功golang
$ 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"
# 安装: 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)
go
: 开发vscode-icons
: 颜值, 彩色文件,目录Material Theme Kit
: 编辑器 UI 主题visual studio code settings sync
: 同步 vscode 配置文件自定义vscodevim
{ "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 }
因为网络缘由可能没法下载(没法上外网)的解决方案:visual-studio-code
cd $GOPATH/src/github.com/golang
,若是没有请建立下载tools
工具:xcode
git clone https://github.com/golang/tools.git tools
将tools
拷贝到 $GOPATH/src/golang.org/x/tools
bash
cp -r $GOPATH/src/github.com/golang/tools $GOPATH/src/golang.org/x/
安装golang debug
插件delve
使用brew install go-delve/delve/delve
或 手动安装
但实际中发现会出现错误,找不到安装包,不知如何解决,改手动安装网络
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命令行工具安装app
xcode-select --install
建立证书编辑器
钥匙串访问
;钥匙串访问
-证书助理
-建立证书
开始建立自签名证书
;让我覆盖这些默认值处
打上勾,选择继续;这样证书就建立好了。
进入$GOPATH/src/github.com/derekparker
,一样,若是没有请自行建立目录
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