DRYな備忘録

Don't Repeat Yourself.

【Go言語】inconsistent definition for type ほげ during import ふが

go test, go build, go runなどで以下のエラーが出る。エディタの警告にも出る。

inconsistent definition for type gorm.search during import struct { db *gorm.
以下略

inconsistent definition for type ほげ ってことで、たぶん同じ名前の違う定義が存在してるんでしょうな。$GOPATH/src以下の定義は常に一意なのだから、$GOPATH/pkg以下のバイナリが怪しいですね。

バイナリ更新すればよさそう

% go clean -i github.com/jinzhu/gorm
% go install github.com/jinzhu/gorm

これで治った。

雑感

go clean って使ったことなかったのでしらべる。

% go help clean

Clean removes object files from package source directories. The go command builds most objects in a temporary directory, so go clean is mainly concerned with object files left by other tools or by manual invocations of go build.

なるほど。今までけっこう直で rm $GOPATH/pkg/darwin_amd64/github.com/otiai10/oppai.aとかしてたけど、本来これ使うべきっぽい。

DRY