by frik · 9y ago · 0 comments
The biggest hurdle with Golang and working on different unrelated projects that are in their own GIT repo. Golang forces you to have one single path were all the code should reside - GOPATH. Name me one other language that has such a restrictive requirement. Why not offer a config?? Beside that I like everything else about Go a lot.
No one forces you to have one single path where your code should reside. It's just an environment variable, so you can have a GOPATH set per project if you wish. It could be your git root.
> Why not offer a config??
That's what they did, or what am I missing?
These are the Go .bashrc lines in my Linux dev desktop:
export GOPATH=${HOME}/go:${HOME}/git_repos
export GOBIN=${HOME}/git_repos/bin
export PATH=$PATH:/usr/local/go/bin:${HOME}/go/bin:${HOME}/git_repos/bin
Note the two different paths in GOPATH?∙ $HOME/go is where "go get foo" puts stuff
∙ $HOME/git_repos is where stuff I'm developing goes (eg $HOME/git_repos/src/github.com/sqlitebrowser/dbhub.io)
The separation means I can backup stuff I'm working on, and exclude the general downloaded Go code from backups as that would just be a waste of space.
Most people do seem to use just one path in GOPATH though, and I remember also doing things that way when first starting out. Not sure why, maybe it's due to some incorrect assumptions given by the Go learning material commonly read when starting out?
I can't understand the GOPATH restriction, I want to put the Go source code where I want. Think about the following projects (Win/Linux doesn't matter, I use both)
One GOPATH doesn't work when you have several projects in different structures e.g.
* D:\Projects\ABC\repo\server\go\src\
* D:\Projects\XYZ\git\backend\go\src\
* T:\svn\go\src\
The Go team does seem to care about the problem though, and they at least made a sane default Go path of $HOME/go, so you can go get right away.