带有GO的Visual Studio代码 - 多个主要声明(启动设置) [英] Visual Studio Code with GO - Multiple main declarations (launch settings)

查看:376
本文介绍了带有GO的Visual Studio代码 - 多个主要声明(启动设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VS代码和Golang的新手。

我有一个包含两种不同服务的现有项目 - 让我们叫一个A和第二个B.

A和B位于同一目录下。



每当我尝试运行A或B时,出现以下错误:

 #目录/目录/目录/ A& B_Directory 
./A.go:12:6:在此块中重新声明
之前在./B处声明.go:18:6

我试着玩 launch.json 文件,添加以下部分:

  {
name:Launch Program ,
type:go,
request:launch,
mode:debug,
program:FullDirectory / A。去

在程序属性中尝试设置为 $ {file} 以及许多其他变体失败。



我喜欢某个方向,我有点迷路。
Thanks。

解决方案

/ strong>,我同意其他人的看法,您应将 service A和B分隔到不同的目录中。

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

  {
version:0.2.0,
configurations:[
{
name:运行当前文件,
type:go,
request:launch,
mode: exec,
program:full-path-to-go.exe,
args:[run,$ {file}],
showLog:true
}
]
}

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

I'm new to VS code and Golang.
I have an existing project containing 2 different services - let's call one A and the second one B.
Both A and B sits under the same directory.

Whenever I try to run A or B, I get the following error :

# directory/directory/directory/A&B_Directory
./A.go:12:6: main redeclared in this block
    previous declaration at ./B.go:18:6

I tried playing with the launch.json file, adding the following sections :

   {
        "name": "Launch Program",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "program": "FullDirectory/A.go"
    }

Also tried in the program attribute to set to ${file} and many other variations that failed.

I'd love for some direction, I'm kinda lost. Thanks.

解决方案

Disclaimer: this is not the recommended approach, I'm agree with others, you shall separate the service A and B into different directory.

Answer to your question: To launch a specific file, use the following configuration to emulate 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
        }
    ]
}

Mode exec is for launching pre-built binary given in the property program (you must specify full path to go binary). Then as the arguments, just add run and filename (${file}) to property args.

这篇关于带有GO的Visual Studio代码 - 多个主要声明(启动设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆