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
+11.8k Golang : Fuzzy string search or approximate string matching example
+7.7k Golang : How to stop user from directly running an executable file?
+15.4k Golang : Delete certain files in a directory
+9.6k Golang : Accessing content anonymously with Tor
+18.6k Golang : Example for RSA package functions
+5.6k Golang : Display advertisement images or strings on random order
+30.2k Golang : Get time.Duration in year, month, week or day
+22.5k Golang : Read directory content with filepath.Walk()
+18.8k Golang : Get download file size
+32.3k Golang : Convert []string to []byte examples
+11.6k Golang : Generate DSA private, public key and PEM files example
+5.2k Golang : Check if a word is countable or not