go list: Usage, Options & Common CI Errors
Query metadata about packages and modules.
go list prints details about packages or, with -m, modules. Its template (-f) and JSON (-json) output make it the go-to tool for scripting package enumeration in CI.
What it does
Reports package or module metadata - import paths, dependencies, files, versions. -m switches to module mode; -u adds available-update info; templates and JSON shape the output for scripts.
Common usage
go list ./... # list all package import paths
go list -m all # list all modules in the build
go list -m -u all # show available updates
go list -json ./... # full JSON metadata
go list -f '{{.ImportPath}} {{.Stale}}' ./...Common CI error: a package fails to load
go list ./... aborts with a load error (e.g. "no Go files in ..." or an import that does not resolve) and your script stops. Fix: add -e so go list reports the error per-package and continues, letting you enumerate the rest; resolve the underlying import or build-tag issue separately.
Options
| Flag | Effect |
|---|---|
| -m | Operate on modules |
| -u | Show available updates (with -m) |
| -json | JSON output |
| -f <tmpl> | Format with a template |
| -e | Tolerate load errors |