El Capitanでgolang 1.7.1の環境構築
インストール
Homebrew からインストール
$ brew update && brew install go
以前はクロスコンパイル用に -with-cc-all とか --cross-compile-all というオプションがあったけど今はないみたい
$ brew info go
go: stable 1.7.1 (bottled), HEAD
(略)
==> Options
--without-cgo
Build without cgo
--without-godoc
godoc will not be installed for you
--without-race
Build without race detector
ワークスペースつくる
Go 言語は単一のワークスペースを使って開発する必要があり go get をしたときのパッケージも同じ場所に展開される
ユーザディレクトリ直下に go ディレクトリ作るのがベターと思う
$ mkdir ~/go $ vi ~/.bashrc
環境変数とパス
$GOPATH の定義が必須で、加えて便宜上 PATH にも追加する
~/.bashrc に追記
# golang export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin
確認
$ go version go version go1.7.1 darwin/amd64
IDE
IntelliJ IDEA の Community エディションをインストールGo Plugin for IntelliJ をいれるCmd + ,-> Plugins -> Browse repositries -> Go をインストールgofmtも最初からつかえるCode -> Go Tools -> Go fmt file
goimportsも$GOPATHにあればつかえる$ go get golang.org/x/tools/cmd/goimportsファイル保存時に自動適用
Debugger は [delve](https://github.com/derekparker/delve/blob/master/Documentation/installation/osx/install.md) を入れると使える
↑IntelliJ IDEA で Go 言語つかうのは設定がいろいろ必要で面倒くさいから使わない方がいい。
初学者にオススメなのは Visual Studio Code - Code Editing. Redefined で Go プラグインさえインストールすれば自動フォーマットや自動インポートも導入してくれるので使いやすい。
あとは Jetbrains 社が Go 用 IDE を本気でつくったのが JetBrains Gogland: Up and Coming Go IDE で、現在はメールアドレスの登録が必要だけどすぐダウンロードできる。機能的にはこれが最強になると思われる。