Go with VSCode on macOS

In this post, i'll try to build a Go development environment on VSCode.

Introduction

I use Emacs as primary text editor. And secondary text editor is VSCode. Exposure to different text editors is very important for getting inspiration.

This assumes that VSCode is already installed on your Mac.
If you doesn't install it, please download here:

How to setup

Install go via Homebrew.

1
brew install go

Open .zshenv, write it.

1
2
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin

Next, install Visual Studio Extension for Go.

./images/figure_02.png

The extention use dlv. So if you finished to install the extention, then run following command:

1
go get -u github.com/go-delve/delve/cmd/dlv

Debugging with VSCode

At first, make .vscode/launch.json.

Here is the launch.json that I used when debugging go-org.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceFolder}/main.go",
            "args": ["render", "test.org", "html"]
        }
    ]
}

Finally, type F5.

./images/figure_03.png