So, about a year ago I wrote a toy go program. It worked beautifully then and was fun to write, it relied on package X. The way I had my GOPATH set up, anything I used 'go get' to obtain would end up somewhere outside of my home folder (I think it was in /opt/go/) while anything I wrote was under /home/ME/code/golang/. The latter directory was all I comitted to my repo (and hence backed up), since I thought anything else my package depended on, like package X, could be retrieved easily by 'go get'ting it again.
Obviously, that was a rather naive idea; as you might have guessed package X has changed significantly since then. After wiping my computer and restoring my repo, the toy program fails to build since package X is so different. So... what's the standard procedure for preventing this kind of problem? The "How to Write Go Code" document briefly says that multiple workspaces (separate entries in GOPATH) are nice, but doesn't explain how to use them effectively.
Back when I wrote that, I was trying to run two workspaces; one for third-party stuff and one to contain all the code I wrote (note: not just the one project). I can see now that that was a silly split, and that my code and package X should be in the same workspace and that both should be committed/backed up. That also has problems though... for instance what if
My first thought was to get rid of the extra GOPATH workspace I had put in /opt/go/ for third-party packages and just have one, and commit everything in it. I don't like that for a few reasons:
- Everything, even totally unrelated projects, in one repo just feels wrong.
- How do I handle new projects, in which perhaps I'd like to use a newer version of package X?
So... what's the recommended approach? All I can think of is changing my GOPATH whenever I change projects, and checking in each all the third-party libraries it depends on for each one. That seems kind of clunky though...