DEV Community

Hui`s Journal of Technology
Hui`s Journal of Technology

Posted on

4 2

How to debug your Go application in VSCode

I am using VScode as my primary editor of coding, and I feel very excited by the VScode ecosystem. However, when I first used it to debug go application, as the debug settings is not that straightforward, I spent one hour to learn how to setup the debug process with VScode.

Before you start, it'd better to install the dlv, the go debugger, manually.

brew install dlv
Enter fullscreen mode Exit fullscreen mode

Validate your dlv installation.

dlv version
Delve Debugger
Version: 1.8.2
Build: $Id: dbb493ec14d1e7753504d016b1e1ef1665b75b16 
Enter fullscreen mode Exit fullscreen mode

Then open VSCode in your root directory of your go project. Usually, in the root directory, you can find your main.go, go.mod, and go.sum files.

Open your debug settings, which is a launch.json file saved in your code directory of ".vscode".

Add the following contents:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch file",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "main.go",
            "args": ["arg1", "arg2"]
        }

    ]
}
Enter fullscreen mode Exit fullscreen mode

Then you can start your debugging by press "F5" now.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay