Hello friends, I'm the new member of the gang. I have questions. I've just started learning golang. As I understand I have to set up stuff for GOPATH and PATH... I'm confused about that. I want to set up these things for just once and ready to code. I like autocomplete and want to use GoSublime plugin for that.
I installed golang with Homebrew. "which go" outputs " /usr/local/bin/go "
Question 1 : for better working space I created /Developer/goprojects . Do I have to set my path stuff for only this directory even I have multiple projects in that folder ?
Question 2: I want to use Sublime's GoSublime plugin for autocomplete and other stuff. Do i need to install https://github.com/nsf/gocode this package in my workspace ?
Question 3: How do you manage your workspace for golang projects ?
Regards.
评论:
Luett_un_Luett:
TheMerovius:Question 1 : for better working space I created /Developer/goprojects . Do I have to set my path stuff for only this directory even I have multiple projects in that folder ?
Set GOPATH=/Developer/goprojects and PATH=${PATH}:${GOPATH}/bin
Question 3: How do you manage your workspace for golang projects ?
I have one GOPATH ("/Developer/goprojects" in your case). What is your question exactly? You have your source repositories under "src" (e.g. "${GOPATH}/src/github.com/<user>/<project>/**"). There is nothing more to manage!?
jahayhurst:Unless you use packages that have the diamond dependency problem (i.e. A depends of B and C, which both depend on D, but on different API versions), which I never had so far, it is not a problem to have only one gopath for everything. Even if you have this problem, you can use vendoring to resolve it transparently to B and C.
So. Just have one gopath for everything. It's fine.
A lot of people btw actually set
GOPATH=$HOME
. And already have `~/bin~ in their path anyway.
lacion:iirc, installing go through homebrew is out of date. I would recommend double checking that - tbh it's not that hard to install go and I just do it by hand - even when I had homebrew.
You should modify your $PATH to include the location for the go system binaries (if they are in
/usr/local/bin
make sure that's there) and maybe set$GOROOT
if needed?You should probably include
$GOPATH/bin
- yourbin
folder within your$PATH
, so you can run stuff easier.Since you're using sublime on OSX, you're also going to want a package called
Fix Mac Path
- sublime on a mac is usually launched by launchctl, which doesn't give you $GOPATH and $GOROOT and $PATH that you just set, so you can set those with that.And, RE #2, you shouldn't need gocode for Sublime (that's for vim and emacs?), but the auto completion for sublime is only based on other patterns that appear in your open buffers (from what I can tell).
jahayhurst:why is installing go with homebrew out of date?
i just did it a few days ago and i got 1.5.1, could you elaborate on why its better to do it by hand?
philsturgeon:If you've got 1.5.1 from Homebrew, it's up to date.
I remember back when 1.4 released, Homebrew was still installing 1.3 iirc. And I want to say a bit before 1.5 hit (a couple of months?) it was still running 1.3. My experience has been that it's out of date - possibly not the case.
That aside, I install it by hand because it's as simple as:
curl https://storage.googleapis.com/golang/go1.5.1.darwin-amd64.tar.gz|tar xf -C /usr/local
And then creating the required directories, and setting env variables - stuff that comes from my dotfiles. Clicking through a pkg install requires me to do stuff, Homebrew requires Homebrew (which I recently moved away from), and I'd rather just automate it independent of everything else.
Take a look at http://getgb.io
