Golang : List all packages and search for certain package
Problem :
You need to find out if a server has the packages that you need to run or compile your Golang source code. What are the tools available to do that?
Solution :
Use go list
command and pipe the output to grep
.
For example, to find out if the gorilla mux package is already imported or not.
go list ... | grep mux
Executing go list ...
will list all packages and pipe the output to grep to check if mux is listed.
IF not, execute go get github.com/gorilla/mux
and repeat go list ... | grep mux
again.
Reference :
http://stackoverflow.com/questions/28166249/how-to-list-installed-go-packages
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+17k Golang : How to get hour, minute, second from time?
+16.6k Golang : Display list of time zones with GMT
+7.9k Golang : Inject/embed Javascript before sending out to browser example
+8.1k Golang : Create unique title slugs example
+13.2k Golang : How to filter a map's elements for faster lookup
+16.8k Golang : Iterating Elements Over A List
+7.9k Golang : Go as a script or running go with shebang/hashbang style
+7.7k Golang : Find duplicate files with filepath.Walk
+38k Golang : UDP client server read write example
+21.6k Golang : Strings to lowercase and uppercase example
+5k Golang : Missing Subversion command
+5k Golang : Convert Chinese UTF8 characters to Pin Yin