Update (2017-10-22)
According to the release notes of the new version of Gogland (EAP 16), the corresponding Go plugin can only be used with IntelliJ IDEA Ultimate from now on. This follows the pattern of providing support for different languages either via a plugin for IntelliJ IDEA Ultimate, or as a standalone IDE, such as PyCharm, Webstorm, or in this case, Goland.
For more details see the related blog post.
Update (2017-04-24)
As an alternative solution that ultimately deals with the OP's problem, I would like to recommend the new IDE specifically for Go development, JetBrains Gogland. The setup is pretty much effortless, but in case you would have difficulties, there is already heplful documentation provided.
Check Gogland, might work for you.
There is also an official plugin that "has everything you could find in Gogland".
In case you are wondering what could be the difference between this new plugin, and the old go-lang-idea-plugin
, check the FAQ article with the explanation.
Original answer
Background info
On OS X Mavericks, Go installed via Macports. Using Go plugin version 0.9.15 with IntelliJ IDEA.
Problem
I wanted to make the IDE understand the imports and provide autocomplete for any package I have installed in GOPATH. (I started creating an app using Revel and were missing the autocomplete...)
Solution
Here is what I did:
- Configure the Go SDK (In menu: View > Open Library Settings > Platform Settings > SDKs).
- Open the "Classpath" tab of the Go SDK you want to set up.
- Add a new item, select the 'src' directory in your $GOPATH.
- Click 'Apply' or 'OK'.
- (not working!?!?, grumble, headache...)
- In menu: File > Invalidate Caches / Restart...
- Click 'Invalidate and Restart'.
- WIN!
Hope this might be what you were looking for!
GOROOT
must reference the folder where you installed GO
GOPATH
must reference an empty folder which will be your workspace (src/pkg/bin for your projects)
Add those two variables in your user environment variables.
A go get github.com/coreos/etcd
should:
- download the sources in
%GOPATH%/src/github.com/coreos/etcd
(src
is created for you)
- compile it in
%GOPATH%/pkg/windows_amd64
(pkg/
is created for you, windows_amd64
reflects your windows architecture)
- with
go install
, install it in %GOPATH%/bin
(bin/
is also created for you)
Note: with Go 1.8+ (Q2 2017), GOPATH
might be set for you by default to (on Windows) %USERPROFILE%/go
.
On Linux, it would be $HOME/go
: see issue 17262.
Update 2018, three years later: GOPATH
is becoming obsolete with Go 1.11 modules:
mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject
Best Answer
I had, in fact, incorrectly set my environment variables. Specifically, when setting GOPATH in my
~/.config/fish/config.fish
file I needed to export the variable.Put these lines in your config.fish for fish shell to use Go:
set -x GOPATH $HOME/path/to/your/workspace
Note the -x. That was what was missing.