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/Homebrewtar xf delve-*.gzgo into directory ( mine is delve-1.0.0-rc.1 )sh scripts/gencert.shit 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 DebuggerVersion: 1.0.0Build: 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版本編號的下載即可
SUCCESS!