Goで依存ライブラリのバージョンを上げる

別のPCでgo getで取得したライブラリのバージョンが違っていたので、ビルドが失敗した。 ライブラリのバージョンを合わせるときに、つまずいたのでその時のメモ。

go version
go version go1.7.3 darwin/amd64

go helpで見たときに、updateの項目がなかった。 ネットで調べたらgo get -uというoptionがあるようだ。

実際に使ってみたら、pullできないと。。。!?

go get -u github.com/jinzhu/gorm

# cd $GOPATH/github.com/jinzhu/gorm; git pull --ff-only
You are not currently on a branch. Please specify which
branch you want to merge with. See git-pull(1) for details.

    git pull <remote> <branch>

package github.com/jinzhu/gorm: exit status 1

コマンドを調べてみたら。。。

go help get
≈
The -u flag instructs get to use the network to update the named packages
and their dependencies.  By default, get uses the network to check out
missing packages but does not use it to look for updates to existing packages.

既存のパッケージの更新を探すものではないと。。。

but does not use it to look for updates to existing packages.

結局やり方がわからなかったので、 masterをcheckoutをして調整をした。。。

cd $GOPATH/github.com/jinzhu/gorm
git checkout master
git pull --ff-only

IntelliJ IDEAでGoを開発しているときに、Unresolved referenceの対応メモ

IntelliJ IDEAでGoの開発をしているときに、Unresolved referenceとエラーがでてコード補完が効かない事があったので、そのときに対応した処理のメモ f:id:kiharekato:20161112201506p:plain

Project Structure -> Modules -> Dependencies -> Module SDK で設定されているGoのversionが古かったので、新しいversionに変更をする。

GVMでGolangのバージョン管理の導入メモ

Go1.4を使用できるように設定

Go1.5以上をcompileするときに必要

git clone -b release-branch.go1.4 https://go.googlesource.com/go $HOME/go1.4
cd $HOME/go1.4/src
./make.bash
echo "export GOROOT_BOOTSTRAP=$HOME/go1.4" >> ~/.bash_profile

gvmをinstallする

1.7.3を使用するように設定

bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
gvm install go1.7.3 
gvm use go1.7.3 --default

GOPATHを設定

HOME/Workspaces/go/ が僕のgoの作業スペースになっている

echo export GOPATH=$HOME/Workspaces/go/ >> ~/.bash_profile
echo export PATH=$PATH:$GOPATH/bin >> ~/.bash_profile