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
+26.7k Golang : Convert file content into array of bytes
+6.6k Golang : Humanize and Titleize functions
+12.3k Golang : Search and extract certain XML data example
+17.9k Golang : Check if a directory exist or not
+4.6k JavaScript: Add marker function on Google Map
+30.3k Golang : Generate random string
+10.4k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+10.6k Android Studio : Checkbox for user to select options example
+18.4k Golang : Write file with io.WriteString
+10.5k Golang : ISO8601 Duration Parser example
+7.2k Golang : Individual and total number of words counter example
+7.4k Golang : Rot13 and Rot5 algorithms example