Tuesday, July 1, 2014

Golang Development via IDE

I use two golang development environments.

  • Text Editor (Sublime)
  • Golang IDE (IntelliJ)

Golang IDE Honorable Mentions

Other Golang Dev IDEs include:

Text Editor

I use Sublime Text + GoSublime for my golang text editor.

Golang IDE

I use Jetbrains tools for a lot of reasons. Here are a few:

  • Go application compilation
  • Syntax highlighting
  • Auto-completion
  • Declaration navigation


For a more complete list see: http://lexsheehan.blogspot.com/2014/03/go-language-intellij-idea-plugin.html

IntelliJ


The Golang plugin only works with IntelliJ.

Fortunately, there is a free "Community" version available here: http://www.jetbrains.com/idea/download/

Install the go-language-intellij-idea-plugin from the menu:

IntelliJ IDEA (main menu) > Preferences ... > Plugins

Click "Install JetBrains plugin..." and enter golang as the search term

Then, click the install button for the go-language-intellij-idea-plugin

Download latest build from: go-lang-plugin-org/go-lang-idea-plugin

And

You'll also need to set the Go SDK in the File > Project Structure > Dependencies

Click New... and the path of the desired Go runtime, e.g., /usr/local/Cellar/go/1.4/libexec


Declaration Navigation Broken?


If you see red warnings with messages that say something like, "cannot find declaration to go to", then from the menu: File > Invalidate Caches / Restart...


Tips on Configuring Your Go Development Environment

Install Go

Before you begin working with Go, use Homebrew to install it.


$ brew install go
$ go version
go version go1.2.2 darwin/amd64


Your go version may be different.

~/.bashrc

Configure GOROOT, GOPATH and PATH in ~/.bashrc

You can also put this in other startup files, but I prefer ~/.bashrc


export GOPATH=$HOME/dev/go
export GOROOT=`go env GOROOT`
export PATH=$PATH:$GOROOT/bin


Homebrew Version

If you used Homebrew to install go, then GOROOT must end in "libexec"; Otherwise, you'll get errors like this:


~/dev/go/samples/src/bitbucket.org/l3x/hello $ go install
hello.go:4:3: cannot find package "fmt" in any of:
 /usr/local/Cellar/go/1.2.2/src/pkg/fmt (from $GOROOT)
 /Users/lex/dev/go/samples/src/fmt (from $GOPATH)
package bitbucket.org/l3x/hello
 imports runtime: cannot find package "runtime" in any of:
 /usr/local/Cellar/go/1.2.2/src/pkg/runtime (from $GOROOT)
 /Users/lex/dev/go/samples/src/runtime (from $GOPATH)


/etc/launchd.conf

Configure GOROOT and GOPATH in /etc/launchd.conf

Create the file if it does not already exist.

setenv GOROOT $GOROOT
setenv GOPATH $GOPATH


Enable launchctl settings without rebooting:


$ launchctl setenv GOROOT $GOROOT
$ launchctl setenv GOPATH $GOPATH


Enable launchctl settings if you start IntelliJ from spotlight.

If you start IntelliJ from the command line, this won't be necessary.

References

http://lexsheehan.blogspot.com/2014/09/go-lang-idea-plugin-incorrect-go-sdk.html
http://lexsheehan.blogspot.com/2014/03/go-language-intellij-idea-plugin.html
http://github.com/go-lang-plugin-org/go-lang-idea-plugin
http://www.sublimetext.com/2
https://github.com/DisposaBoy/GoSublime
http://www.esimov.com/2014/03/new-adeventure-the-go-language
https://github.com/smartystreets/goconvey/wiki/Opening-files-in-your-editor-from-the-Web-UI

This work is licensed under the Creative Commons Attribution 3.0 Unported License.

4 comments:

  1. Hire the best golang development company that offering budget-friendly development services with expert web developers.

    ReplyDelete
  2. Awesome post presented by you..your writing style is fabulous and keep update with your blogs. Hire Golang Development Company

    ReplyDelete
  3. Here is no doubt that you shared informational article over golang development and currently many golang development companies are relying for go language. I hope you will share another article for help to us.

    ReplyDelete
  4. Thanks Lex Sheehan for sharing this short informative article about your Golang development services. If you have any requirement to Hire GoLang Developers for your project. Please visit us.

    ReplyDelete