Top Banner
GoClipse Setup tutorial Version 2 Gianluca Costa http://gianlucacosta.info/
23

GoClipse - Setup tutorial - Version 2

Jul 14, 2015

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • GoClipse Setup tutorial

    Version 2

    Gianluca Costa

    http://gianlucacosta.info/

  • Brief introduction to GoClipse

    Very nicely integrated within the 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)

  • Brief introduction to GoClipse (2)

    Employs Gocode to provide 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

  • About this tutorial This tutorial schematically describes a

    possible 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! ^__^

  • Full installation1)Install Go and set up your GOROOT2)Set up your GOPATH3)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 administer6)Install GoClipse7)Configure GoClipse

  • Minimal installation

    1)Install Go only if it's not on your machine, but always set up your GOROOT

    2)Set up your GOPATH3)Download just the Eclipse Platform - only if

    you can't reuse an existing Eclipse installation4)Install GoClipse5)Configure GoClipse

  • Setting environment variables If you are on a BASH-based 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

  • Install Go and set up your GOROOT

    Download Go 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

  • Set up your GOPATH

    Create a directory dedicated to 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

  • Install Git

    Git seems required in order to automatically 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/

  • Install Gocode

    From the command line, run:

    go get -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

  • Install Mercurial

    Mercurial seems required in order to download 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/

  • Install Go oracle

    From the command line, execute:

    go get code.google.com/p/go.tools/cmd/oracle

    This might take a few minutes and will not output anything in case of success

  • Install Eclipse Multiple installations of Eclipse can coexist on

    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

  • Install GoClipse

    GoClipse can be installed like most Eclipse plugins

    For detailed installation instructions, please refer to: https://github.com/GoClipse/goclipse/blob/latest/documentation/Installation.md#installation

    A basic version of CDT (C/C++ Development Tooling) might be automatically installed as well

  • The workspace and the GOPATH

    First of all, if 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

  • Configure GoClipse

    1)Before configuring GoClipse, choose your workspace, because settings are saved in the workspace itself

    2)Within Eclipse, click on the Window ==> Preferences... menu item

    3)Select the Go section

  • Configure GoClipse (2) - General

    The values of GOROOT 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

  • Configure GoClipse (3) - Tools

    Open the Tools subsection 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

  • Creating a Go project

    When creating a new Go 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

  • Create a main file

    1)Right-click on the project's src folder2)Choose New=>Folder3)Call it, for example, MyProgram4)Right-click on it and choose New=>Go File5)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

  • A minimal source file

    package main

    import "fmt"

    func main() { fmt.Println("Hello, world! ^__^")}

  • Build artifacts

    Your PROJECT_DIR/bin directory will contain a MyProgram 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

    Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23