# vscode golang debug程序配置方法

By [ijaa](https://paragraph.com/@ijaa) · 2022-01-12

---

1.在项目根目录下的.vscode目录创建launch.json文件

2.文件内容模版如下：

    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "go",
                "request": "launch",
                "mode": "auto",
                "program": "${workspaceRoot}/main.go", // main.go文件路径
                "buildFlags":"-mod=vendor", // 使用vendor模式或者为空
                "env": {"xxxEnv":"on"}, // 自定义环境变量
                "args": ["-config","xxx.toml"] // 自定义启动参数
            }
        ]
    }
    

3.上述模版中的buildFlags，env，args可根据具体编译及运行需要进行调整

---

*Originally published on [ijaa](https://paragraph.com/@ijaa/vscode-golang-debug)*
