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
+7.2k Golang : How to get garbage collection data?
+13.5k Golang : Execute terminal command to remote machine example
+6.3k Golang : Gonum standard normal random numbers example
+10.3k Golang : "https://" not allowed in import path
+4.4k Golang : Detect variable or constant type
+3.5k Python : Convert(cast) bytes to string example
+33k Golang : Convert date or time stamp from string to time.Time type
+4.7k CodeIgniter : form input set_value cause " to become & quot
+12.2k Golang : Get current time from the Internet time server(ntp) example
+4.5k Golang : Extract XML attribute data with attr field tag example
+9.9k Swift : Convert (cast) Int or int32 value to CGFloat