MacでGo開発環境を構築する その2
前回はMacに普通にGo環境を構築しました
その流れのままWebフレームワークを試していこうと思ったのですが、仮想環境の作り方とかなんにも知らんなーってことで引き続き環境的なところを学ぼうと思います
環境(goenv+direnv+ glide)
goenvは、go言語のバージョンを管理するやつらしい
direnvはPythonでいうところの venv
?
glideは外部ライブラリをyamlで管理しインストールしてくれるpackage.jsonみたいなやつぽい
なにはともあれやってみましょう
インストール
$ brew install goenv $ brew install direnv $ brew install glide
Go環境
$ goenv install 1.10.0
go-exmaple $ goenv install 1.10.0
Downloading go1.10.darwin-amd64.tar.gz...
-> https://dl.google.com/go/go1.10.darwin-amd64.tar.gz
Installing Go Darwin 64bit 1.10.0...
Installed Go Darwin 64bit 1.10.0 to /Users/chichi1091/.goenv/versions/1.10.0
仮想環境作成
$ direnv edit .
viかvimが起動するので以下を記載する
export GOBIN=$(pwd)/bin export GOPATH=$(pwd):$GOPATH export PATH=$PATH:$GOBIN
glideの設定
このようなディレクトリ構成を作ります
. └── src └── app ├── main.go └── vendor
app
ディレクトリに移動して以下のコマンドを実行すると glide.yaml
が作られます
$ glide create [INFO] Generating a YAML configuration file and guessing the dependencies [INFO] Attempting to import from other package managers (use --skip-import to skip) [INFO] Scanning code to look for dependencies [INFO] Writing configuration file (glide.yaml) [INFO] Would you like Glide to help you find ways to improve your glide.yaml configuration? [INFO] If you want to revisit this step you can use the config-wizard command at any time. [INFO] Yes (Y) or No (N)? Y [INFO] Looking for dependencies to make suggestions on [INFO] --> Scanning for dependencies not using version ranges [INFO] --> Scanning for dependencies using commit ids [INFO] Gathering information on each dependency [INFO] --> This may take a moment. Especially on a codebase with many dependencies [INFO] --> Gathering release information for dependencies [INFO] --> Looking for dependency imports where versions are commit ids [INFO] No proposed changes found. Have a nice day.
使いたい外部ライブラリは以下のコマンドで追加することができる
$ glide get github.com/xxx/xxx
glide.yamlがある状態で記載されている外部ライブラリを全て取得したい場合は glide up
を実行すればいいらしい
こんな感じでいいのかな?
次回は基本文法のお勉強をしてみようと思います