7

I am having trouble understanding what the following command does.

go list ./...

When I look at the official documentation https://golang.org/cmd/go/#hdr-List_packages, it is not clear to me what the ./... argument is telling the command.

Raghav
  • 127
  • 2
  • 7

2 Answers2

9

go list requires an import path for a package and can give you some listing info for the packages matched this way (you may be interested in its -f flag).

./... is a wildcard that matches the current folder and all of its subfolders (execute go help packages to read more about this somewhat hidden feature), and that can be used with all the built-in Go commands.

So go list ./... can list all the Go packages in the current folder and its sub-folders - you may want to call it from GOPATH for example.

Dimitar Dimitrov
  • 16,032
  • 5
  • 53
  • 55
  • 1
    When using Go modules, `go list ./...` will also download all dependencies (except for dependencies used by tests I think). This can be a handy way to install production dependencies in a Dockerfile for example. Although if you're going to run `go install` or `go run` right afterwards, then you don't need `go list` since `install` or `run` will install dependencies automatically. – Matt Browne Jul 09 '20 at 17:39
  • Addendum: dependencies are automatically downloaded when running `go build` too. So I guess the use case for explicitly downloading dependencies is pretty limited. – Matt Browne Jul 09 '20 at 17:49
1
go list ./...

Here ./ tells to start from the current folder, ... tells to go down recursively.

go list ...

In any folder lists all the packages, including packages of the standard library first followed by external libraries in your go workspace.

Emdadul Sawon
  • 5,730
  • 3
  • 45
  • 48