Skip to content

Instantly share code, notes, and snippets.

@keisatou
Last active December 30, 2015 12:29
Show Gist options
  • Save keisatou/7829311 to your computer and use it in GitHub Desktop.
Save keisatou/7829311 to your computer and use it in GitHub Desktop.
https://github.com/hashicorp/serf/blob/master/Makefile で使われてる以下のgoの文法の意味調べる:
go list -f '{{range .TestImports}}{{.}} {{end}}' ./...
まず-fはフォーマットの指定。詳しくはgo help listを見る。
引数の./...はgo help packagesによると
As a special case, x/... matches x as well as x's subdirectories.
For example, net/... expands to net and packages in its subdirectories.
らしい。
$ pwd
/Users/keisatou/go/src/github.com/hashicorp/serf
# フォーマット指定無し:
go list ./...
github.com/hashicorp/serf
github.com/hashicorp/serf/command
github.com/hashicorp/serf/command/agent
github.com/hashicorp/serf/serf
github.com/hashicorp/serf/testutil
# フォーマット指定有り:
$ go list -f '{{range .TestImports}}{{.}} {{end}}' ./...
encoding/base64 fmt github.com/hashicorp/serf/command/agent github.com/hashicorp/serf/serf github.com/hashicorp/serf/testutil github.com/mitchellh/cli io math/rand net os strings testing time
bytes encoding/base64 flag fmt github.com/hashicorp/logutils github.com/hashicorp/serf/serf github.com/hashicorp/serf/testutil github.com/mitchellh/cli io io/ioutil log math/rand net os path/filepath reflect strings testing time
fmt github.com/hashicorp/memberlist github.com/hashicorp/serf/testutil io/ioutil log os reflect sort strings testing time
$ go list -f '{{range .TestImports}}{{.}} {{end}}' ./... | wc
3 43 546
あれ?フォマットの有り無しで出力内容も変わってる?
go help listによると、デフォルトは'{{.ImportPath}}'らしい。
rangeは関数?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment