[GO基礎(chǔ)] - mac環(huán)境配置與測試運行

golang環(huán)境安裝

brew install golang
保險起見可以先brew update

IDE安裝

可以直接使用sublime、webstrom、eclipse等,在這里我使用的是VSCode

  • sublime: 沒辦法跑測試
  • eclipse: 翻墻下載go插件好坑~~

Delve調(diào)試環(huán)境安裝

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

設(shè)置好后重新安裝

命令行dlv version

Delve Debugger
Version: 1.0.0
Build: v1.0.0

IDE啟動

檢測最簡單的服務(wù)器代碼

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, 簡單粗暴

調(diào)試

提示錯誤:debugserver or lldb-server not found: install XCode's command line tools or lldb-server
老版本解決辦法:xcode-select --install
新版本不再有這個工具,只能去開發(fā)者網(wǎng)站下載:https://developer.apple.com/download/more/
找到自己對應(yīng)系統(tǒng)和xcode版本編號的下載即可

SUCCESS!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容