Skip to content
This repository has been archived by the owner on Mar 30, 2018. It is now read-only.

Go Development Portal

Shahryar Sedghi edited this page Apr 18, 2016 · 6 revisions

This page is for notes, tips, and suggestions for Go development

Debugging

The Golang corpus does not include a native debugger. It is possible to attach GDB to a go program, but the results are often disappointing on account of a lack of insight into the Go runtime (such as goroutines, etc). The obvious and perhaps idiomatic way to debug a Go application is with the tried and true printf+iterate model. However, there are several options above and beyond that may make certain problems easier to find.

Delve

derekparker/delve is a third party project that offers a comprehensive gdb-like, yet go-aware debugger. We won't reiterate the description or documentation here, but if you are looking for a way to debug a nasty problem, Delve does a pretty decent job.

A few helpful tips

You can run your go program with arguments (similar to gdb's "set arg") using the "--" parameter, as per here

Forcing a stack trace in a hung program

kill -ABRT is a useful way to generate a stack trace of all goroutines, helpful if your program appears hung.

GOClipse & Eclipse

The following steps show how to setup and use Eclipse with GOLang for debugging and other IDE use

  • Eclipse Mars is the minimum Pre-req
  • Java 8 is required to run GOClipse

Install Eclipse J2EE from eclipse.org

http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/mars2

Get GoClipse prerequisites

  • go get github.com/nsf/gocode
  • go get golang.org/x/tools/cmd/oracle

Install and setup GoClipse

  • Start Eclipse and accept default workspace, by clicking on Eclipse executable in the root of Eclipse directory
  • From File Menu→ Help→ Install New Software → and click the add button
  • Set the location to http://goclipse.github.io/releases and name it goclipse
  • Click on OK
  • Wait for the list to get populated
  • Choose GoClipse from the list as follows:
  • Click on Next and accept all later on
  • Restart Eclipse after install
  • From File Menu → Eclipse → Preferences → Go
  • Set GOROOT to /usr/local/go
  • Accept the Gopath and projects
  • Switch to Go→ Tools
  • Browse to gocode, oracle and godef which has been already installed in $GOPATH/bin
  • Accept all other defaults
  • Click on OK

Build a GO project

  • File Menu → New → Go Project
  • Name the project
  • Uncheck Use Default location
  • Type in the GOPath location in the Directory field
  • Click on Finish

Any source code in GOPath/src is accesssible to debug and run in Eclipse