Search code examples
gotoolchain

How to list imported module on a go source code directory


Is there an tool or easiest way to list all imported packages on go source code directory? for example:

$ go list_imports a_directory/
github.com/bla/bla
github.com/foo/bar
LOCAL/module/path

Solution

  • Ah found the way..

    go list -f '{{join .Deps "\n"}}' |  xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}} ' | sort | uniq