Skip to content

Instantly share code, notes, and snippets.

@huanghantao
Last active January 2, 2020 08:45
Show Gist options
  • Save huanghantao/4cb815420a5c0b02c16e86e51a5cdbf5 to your computer and use it in GitHub Desktop.
Save huanghantao/4cb815420a5c0b02c16e86e51a5cdbf5 to your computer and use it in GitHub Desktop.

vscode配置--golang.md

launch.json文件

主要是代码调试用的。

主函数配置文件:

{
    "name": "main.go",
    "type": "go",
    "request": "launch",
    "mode": "auto",
    "program": "${workspaceRoot}/main.go",
    "cwd": "${workspaceRoot}",
    "env": {
        "http_proxy": ""
    },
    "args": [
        "-cfg",
        "${workspaceRoot}/config/dev/config.toml",
        "-in",
        "${workspaceRoot}/config/project/project.toml",
    ],
    "dlvLoadConfig": {
        "followPointers": true,
        "maxVariableRecurse": 1,
        "maxStringLen": 512,
        "maxArrayValues": 64,
        "maxStructFields": -1
    }
}

单元测试配置文件:

{
    "name": "go test",
    "type": "go",
    "request": "launch",
    "mode": "test",
    "program": "${file}",
    "env": {
        "http_proxy": ""
    },
    "args": [
        "-cfg",
        "${workspaceRoot}/config/dev/config.toml",
        "-in",
        "${workspaceRoot}/config/project/project.toml",
    ],
    "showLog": true,
    "dlvLoadConfig": {
        "followPointers": true,
        "maxVariableRecurse": 1,
        "maxStringLen": 512,
        "maxArrayValues": 64,
        "maxStructFields": -1
    }
}

debug test功能不支持传入go.testFlags,并且run test功能不支持调试,所以只可以通过配置launch.json文件,然后按F5来进行单步调试。因为go test是按照测试函数定义的顺序来执行的,所以,必须要在测试的时候调用t.Parallel()来并发执行测试,然后在需要调试的测试函数处设置断点来进行调试。

settings.json文件

主要是为golang插件用的。

{
    "debug.node.autoAttach": "on",
    "go.vetOnSave": "package",
    "editor.formatOnSave": true,
    "go.lintOnSave": "package",
    "go.buildTags": "",
    "go.buildFlags": [],
    "go.lintTool": "golint",
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.useCodeSnippetsOnFunctionSuggest": true,
    "go.formatTool": "goimports",
    "go.formatFlags": [],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment