Blog about software development


Debugging Go with VSCode and Delve

30 Apr 2016 - by 'Maurits van der Schee'

Go, a programming language (by Google), is now supported by Visual Studio Code (by Microsoft). It has step-by-step debugging support thanks to the Delve debugger. I am very impressed with Visual Studio Code and it's support for the Go language. I am running Ubuntu 16.04 and everything worked flawless and even when I was missing some packages Visual Studio Code nicely informed me how to solve this.

Installation of Go

First we install Go and set the GOPATH variable in the ".bashrc" file:

sudo apt-get install golang 
mkdir go
export GOPATH=$HOME/go
echo 'export GOPATH=$HOME/go' >> .bashrc

In the last line we make sure that next time we login the GOPATH is set properly.

Installation of Visual Studio Code

Now download and install Visual Studio Code using:

wget --content-disposition https://go.microsoft.com/fwlink/?LinkID=760868
sudo dpkg -i vscode-amd64.deb

After that we install the dependencies for the go extension:

go get -u github.com/rogpeppe/godef
go get -u github.com/golang/lint/golint
go get -u github.com/derekparker/delve/cmd/dlv
go get -u github.com/tpng/gopkgs

Now we can start Visual Studio Code and press Ctrl-Shift-P and type "ext install Go" to install the extension. You are ready! Open your Go project and be amazed!

About Atom's go-plus

Atom is another popular editor nowadays and it also has Go support. To install a whole set of Go related packages it is enough to just search and install the package "go-plus". In Atom you click "Edit", then "Preferences", then "Install" and you type "go-plus", press enter to search and click the blue "Install" button.

In order to make this work I had to manually set the GOPATH environment variable in Atom. I had to click: "Edit", then "Init Script...", this opens "init.coffee" in which I added the line:

process.env['GOPATH'] = '/home/maurits/go'

After installation it was working, but running and debugging was not integrated and was still to be done from the command line. This is not a problem for me, but the Visual Studio Code experience was smoother.

About LiteIDE X29

I tried it (even the new version X29) and I did not like it as much as the above two editors. Mainly because I cannot get used to the weird GUI that the program has. As a positive point I can mention that it is a very light weight IDE (as the name already suggests).


PS: Liked this article? Please share it on Facebook, Twitter or LinkedIn.