带GO的Visual Studio代码 - 多个主要声明(启动设置)

Dot*_*rog -1 go visual-studio-code vscode-settings

我是VS代码和Golang的新手.
我有一个包含2个不同服务的现有项目 - 让我们调用一个A和第二个B.A
和B都位于同一目录下.

每当我尝试运行A或B时,我都会收到以下错误:

# directory/directory/directory/A&B_Directory
./A.go:12:6: main redeclared in this block
    previous declaration at ./B.go:18:6
Run Code Online (Sandbox Code Playgroud)

我尝试使用该launch.json文件,添加以下部分:

   {
        "name": "Launch Program",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "program": "FullDirectory/A.go"
    }
Run Code Online (Sandbox Code Playgroud)

还尝试在program属性中设置为${file}失败的许多其他变体.

我喜欢某个方向,我有点失落.谢谢.

put*_*utu 6

免责声明:这不是推荐的方法,我同意其他人,您应将服务 A和B分成不同的目录.

回答您的问题:要启动特定文件,请使用以下配置进行模拟go run current-file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Run current file",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "program": "full-path-to-go.exe",
            "args": ["run", "${file}"],
            "showLog": true
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

模式exec用于启动属性中给出的预构建二进制文件program(必须指定go二进制文件的完整路径).然后作为参数,只需添加run和filename(${file})属性args.