golang环境安装
brew install golang
保险起见可以先brew update
IDE安装
可以直接使用sublime、webstrom、eclipse等,在这里我使用的是VSCode
- sublime: 没办法跑测试
- eclipse: 翻墙下载go插件好坑~~
Delve调试环境安装
brew install go-delve/delve/delve
检查是否安装成功dlv version
,提示不存在该命令
解决办法
cd $HOME/Library/Caches/Homebrew
tar xf delve-*.gz
go into directory ( mine is delve-1.0.0-rc.1 )
sh scripts/gencert.sh
it will asks for password, and you're done.
After that just re run brew install go-delve/delve/delve
参考:https://github.com/go-delve/homebrew-delve/issues/19#issuecomment-330442033
设置好后重新安装
命令行
dlv version
Delve Debugger
Version: 1.0.0
Build: v1.0.0
IDE启动
检测最简单的服务器代码
func HelloServer1(w http.ResponseWriter, req *http.Request) {
fmt.Fprint(w,"hello world")
}
func main() {
http.HandleFunc("/test", HelloServer1)
err := http.ListenAndServe(":23456", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}
报错如下
compile: version "go1.9" does not match go tool version "go1.9.1"
参考:https://stackoverflow.com/questions/46693653/compile-version-go1-9-does-not-match-go-tool-version-go1-9-1
解决办法 export GOROOT=/usr/local/opt/go/libexec
, 简单粗暴
调试
提示错误:debugserver or lldb-server not found: install XCode's command line tools or lldb-server
老版本解决办法:xcode-select --install
新版本不再有这个工具,只能去开发者网站下载:https://developer.apple.com/download/more/
找到自己对应系统和xcode版本编号的下载即可