Help us understand the problem. What is going on with this article?

$GOPATH/binにいるバイナリ群の出自を探る方法

More than 1 year has passed since last update.

Goを使っていると、ある日突然に日頃使っていたコマンドが全く違う何かに置き換えられていたりして、驚くことがあります。
$GOPATH/bin の下に色々入ってはいるものの、どこの誰かは名前だけではわかりません。

結論

シェルスクリプト

go list を使って、インストールパッケージパス一覧を出してみます。

go list -f "{{if eq \"${GOPATH}/bin/\" (printf \"%.$((${#GOPATH}+5))s\" .Target)}}{{.Target}},{{.ImportPath}}{{end}}" all

結果サンプル

パス見てみると、 vendor とか、 examples とか、ちらほらと治安悪いですね。
examples/.../server は鬼畜の所業としか思えないですね。(またgo-swaggerか…)

/Users/user/go/bin/toml-test-decoder,github.com/BurntSushi/toml/cmd/toml-test-decoder
/Users/user/go/bin/toml-test-encoder,github.com/BurntSushi/toml/cmd/toml-test-encoder
/Users/user/go/bin/tomlv,github.com/BurntSushi/toml/cmd/tomlv
/Users/user/go/bin/go-symbols,github.com/acroca/go-symbols
/Users/user/go/bin/gometalinter,github.com/alecthomas/gometalinter
/Users/user/go/bin/codegen,github.com/alecthomas/gometalinter/vendor/github.com/nicksnyder/go-i18n/i18n/language/codegen
/Users/user/go/bin/embedi18n,github.com/alecthomas/gometalinter/vendor/gopkg.in/alecthomas/kingpin.v3-unstable/cmd/embedi18n
/Users/user/go/bin/genvalues,github.com/alecthomas/gometalinter/vendor/gopkg.in/alecthomas/kingpin.v3-unstable/cmd/genvalues
/Users/user/go/bin/gotests,github.com/cweill/gotests/gotests
/Users/user/go/bin/gomodifytags,github.com/fatih/gomodifytags
/Users/user/go/bin/motion,github.com/fatih/motion
/Users/user/go/bin/swagger,github.com/go-swagger/go-swagger/cmd/swagger
/Users/user/go/bin/server,github.com/go-swagger/go-swagger/examples/2.0/petstore/server
/Users/user/go/bin/petstore-server,github.com/go-swagger/go-swagger/examples/generated/cmd/petstore-server
/Users/user/go/bin/countdown-server,github.com/go-swagger/go-swagger/examples/stream-server/cmd/countdown-server
/Users/user/go/bin/agg,github.com/go-swagger/go-swagger/vendor/github.com/kr/text/cmd/agg
/Users/user/go/bin/mc,github.com/go-swagger/go-swagger/vendor/github.com/kr/text/mc
/Users/user/go/bin/cmd,github.com/go-swagger/go-swagger/vendor/github.com/pelletier/go-toml/cmd
/Users/user/go/bin/tomljson,github.com/go-swagger/go-swagger/vendor/github.com/pelletier/go-toml/cmd/tomljson
/Users/user/go/bin/tomll,github.com/go-swagger/go-swagger/vendor/github.com/pelletier/go-toml/cmd/tomll

解説

追記予定

余談

server という python -m SimpleServer をちょっと拡張しただけのシェルを自作で使っていたのですが、いつのまにか使えなくなってしまい、 which server としてみたところ、 ~/go/bin/server が返ってきてなんじゃこりゃと思ったり…割と怖い話。

追記予定

  • package mainを迂闊に書くべきじゃない
  • sampleならsampleのタグを入れるといいかも? // +build sample
  • その辺ガイドライン的なものは無いのか
  • $PATH$GOPATH/binを入れるべきではないかもしれない
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away