How to configure Visual Code Studio with Go for debugging

First of all we need to install Delve, it's a debugger for Go.

https://github.com/go-delve/delve/blob/master/Documentation/installation/osx/install.md

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

If you didn't enable Developer Mode using XCode you will be asked to  authorize the debugger every time you use it. To enable Developer Mode  and only have to authorize once per session use:

sudo /usr/sbin/DevToolsSecurity -enable

Now, you need to open your golang file on Visual Code and click in the debug menu.

Here, you could have an error, so, open the launch.json file and add:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "remotePath": "",
            "port": 2345,
            "host": "127.0.0.1",
            "program": "${fileDirname}",
            "env": {},
            "args": [],
            "showLog": true
        }
    ]
}

Restart VC and check it again, it should be working now.

Juan Pablo Arias

I constantly discover new technologies and ways to improve IT processes. I'm a fan of automation. I like programming, but my passion is cloud computing.