Is there a way in Go to list all the standard/built-in packages (i.e., the packages which come installed with a GoLang installation)?
I have a list of packages and I want to figure out which packages are standard.
Is there a way in Go to list all the standard/built-in packages (i.e., the packages which come installed with a GoLang installation)?
I have a list of packages and I want to figure out which packages are standard.
If you want a simple solution, you could check if a package is present in $GOROOT/pkg. All standard packages are installed here.
Use the
go list std
command to list the standard packages. The special import pathstd
expands to all packages in the standard Go library (doc).Exec that command to get the list in a Go program:
You can use the new
golang.org/x/tools/go/packages
for this. This provides a programmatic interface for most ofgo list
:To get a
isStandardPackage()
you can store it in a map, like so: