Richard Bucker

to Golang HOME or some place else?

Posted at — Mar 21, 2015

I’m trying to cleanup all the junk on my computer; and there is a lot of junk. The hard part is the quantity of files not the size. As part of the Golang idiomatic way there are at least 3 places where “we” store packages.(a) GOROOT - which is typically reserved for the compiler. Go’s get function may let you do it if you override GOPATH for that request but it’s probably not the best thing to go.(b) setting GOPATH=$HOME - this is the usual way to do things, however, this means you are going to end up with a src, pkg, and bin folder in your $HOME. This is not a totally bad thing but just messy. Partly because you have 3 new folders in your HOME but you could inadvertently override another executable with the same name in your bin folder… as this bin folder is shared between your normal apps and your apps from source.This is further messy because the order of the paths in the PATH environment variable is the order that they are evaluated when looking for an executable… so you could end up executing the wrong one.(c) setting GOPATH=$HOME/gorepo - this means that the 3 folders I mentioned would be located in the gorepo folder. This seems better because we have segregated the packages and binaries from the rest of my everyday stuff. Development is partitioned away from the every day.Now the only concern is that while I’m importing code from every corner of the github and bitbucket universe I’m polluting my gorepo folder with code that I did not write but with vendor code that others did. Frankly there are times when I just like to clear the decks and delete the vendor code. Now what do to?create a gorepo and put my code in thereinside gorepo create a vendor folder shared by allimplement proper project vendoring when applicablemake sure my projects use the proper folder structure that maps to the VCS pathfork projects to your repo when practical“configuration as code” - use a Makefile with simple commandsthat should do it… even though it still means having more that one path in your GOPATH.QUESTION: Where do you put repos that you want to inspect, fiddle and possibly fork later on? Since the full path is part of the namespace if your fiddling includes importing these projects you’re going to be forced into changing the imports. So maybe “import early”?UPDATE: Rats! Maybe GOPATH is just better being $HOME and sucking up the deps in the same folder?UPDATE: Andrew Gerand wrote a good article on the subject.