Eclipse IDE • Can automatically build projects whenever a file is saved, showing errors in the editor and in the Problems window • Supports Go projects whose source files are in directories not listed in the GOPATH (see later)
very fast code completion (e.g., when you press . Or Ctrl+Space while writing an identifier) • Employs Go oracle to support enhanced source code navigation: pressing F3 or clicking on a name while pressing Ctrl works like a hyperlink to its definition, even for standard library modules
solution for setting up Go, GoClipse (current version: 0.9.1) and a few related tools • We'll take into account 2 similar paths: – A full-fledged installation, with a few optional components – A minimal setup, which can be handy if you need a standalone copy of GoClipse alongside another version of Eclipse • Feel free to experiment! ^__^
up your GOPATH 3)Install Git and the latest version of Gocode, for faster autocompletion (optional) 4)Install Mercurial and the latest version of Go oracle, for accurate symbol browsing (optional) 5)Install any edition of Eclipse - or reuse an installation that you already administer 6)Install GoClipse 7)Configure GoClipse
machine, but always set up your GOROOT 2)Set up your GOPATH 3)Download just the Eclipse Platform - only if you can't reuse an existing Eclipse installation 4)Install GoClipse 5)Configure GoClipse
Unix, environment variables can be set by editing the .profile configuration file (or .bashrc – it depends on your operating system) in your home directory. For example, you could add the following line: export MY_ENV_VAR=$HOME/MyDir • If you are on a recent version of Windows, right-click on the This PC icon on the Desktop, choose Properties, then Advanced system settings, then Environment variables
from https://golang.org/ and install it: the specific procedure depends on your OS • Go might already be available on your system! Use which go or where go to find out! • Set the env. var. GOROOT to the absolute path of Go's installation directory (e.g., /opt/go on a Unix system, or C:\Go on Windows) • Add the GOROOT/bin subdirectory to your PATH environment variable
your GoPath, for example /home/myself/gopath or C:\GoPath • Set up a global environment variable called GOPATH, pointing to that directory • Add GOPATH/bin to your PATH, although such directory doesn't exist yet • GOPATH can be not only a single directory, but a list of directories: for further info, please refer to:https://golang.org/doc/code.html
download Gocode via “go get” • Most Linux distributions have the related installation packages in their repositories, and Git's website provides several binaries • Official website: http://git-scm.com/
-u github.com/nsf/gocode (on Unix) go get -u -ldflags -H=windowsgui github.com/nsf/gocode (on Windows) • The program might take a few minutes and will not produce output in case of success
Go oracle via “go get” • Just like Git, it is already in the software repositories of most Linux distributions, and its website provides many binary packages • Official website: http://mercurial.selenic.com/
the same system – the only caveat usually consisting in keeping their respective workspaces separated • If you want to install a minimal Eclipse version dedicated to GoClipse, you might want to download just the Eclipse Platform, currently available at: http://download.eclipse.org/eclipse/downloads/ drops4/R-4.4.1- 201409250400/#PlatformRuntime
plugins • For detailed installation instructions, please refer to: https://github.com/GoClipse/goclipse/blob/late st/documentation/Installation.md#installation • A basic version of CDT (C/C++ Development Tooling) might be automatically installed as well
you are setting up an Eclipse version dedicated to GoClipse, you'll probably want to keep the workspace separated from other Eclipse workspaces, to prevent conflicts • The workspace should reside in an arbitrary directory outside GOPATH • Your source code can be located either below a per-project src folder or below an src folder of your GOPATH: for the sake of simplicity, we'll focus on the first case
and GOPATH should match the values of the same environment variables previously defined • Choose a value for GOOS and GOARCH, according to your current development platform. This seems useful for source code navigation • Check the remaining executable paths
• Click the Browse... buttons to select the actual path of your oracle and gocode executable files (to find them easily, consider that they should reside in GOPATH/bin) • You might want to disable the Enable Gocode log console checkbox • Confirm the dialog and restart Eclipse
project, select the option Create new project in workspace: while you work on that project, GoClipse will automatically prepend the project's directory to your GOPATH • On the other hand, by choosing Create project from existing source, you could work on an arbitrary source dir of your GOPATH
2)Choose New=>Folder 3)Call it, for example, MyProgram 4)Right-click on it and choose New=>Go File 5)In the dialog, select Command Source File, then Empty Main Function, and call it, for example, main.go 6)Write your source file (see next slide) and save it: GoClipse should already build the program for you
executable, where MyProgram is the name of the directory containing the main package • Additionally, every custom Go package within your project will create a related .a library file in the PROJECT_DIR/pkg/GOOS_GOARCH directory tree • If source files are decoupled from the project, the related GOPATH is used in lieu of PROJECT_DIR