Go - See what packages my app imports

It’s often practical to see what packages your app is importing. Unfortunately there isn’t a simple way to do that, however it is doable via the go list tool and using templates.

Go to your app and run the following.

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

Here is an example with the clirescue refactoring example:

$ cd $GOPATH/src/github.com/GoBootcamp/clirescue
$ go list -f '{{join .Deps "\n"}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'
github.com/GoBootcamp/clirescue/cmdutil
github.com/GoBootcamp/clirescue/trackerapi
github.com/GoBootcamp/clirescue/user
github.com/codegangsta/cli

If you want the list to also contain standard packages, edit the template and use:

$ go list -f '{{join .Deps "\n"}}' |  xargs go list -f '{{.ImportPath}}'
 爱 老子 - 「道 德 經」 

Comments

©2015-2021 Alimy All rights reserved.