Jay Taylor's notes

back to listing index

How to get golang package import list

[web search]
Original source (pmcgrath.github.io)
Tags: golang go imports gopher-tricks pmcgrath.github.io
Clipped on: 2017-05-04

How to get golang package import list

Oct 21, 2014

This page contains the data that is available to the go list command, we use golang templates to extract subsets of this data below

Get imports for the current directory package

go list -f '{{range $imp := .Imports}}{{printf "%s\n" $imp}}{{end}}' | sort

This lists all the imports for the current package

Get list of non standard dependencies

go list -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}'

This lists all the non standard dependencies for the current package

Various tech tidbits that I want to record.