问题描述
我是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分隔到不同的目录中。 回答您的问题:要启动特定文件,请使用以下配置来模拟 模式 I'm new to VS code and Golang. Whenever I try to run A or B, I get the following error : I tried playing with the Also tried in the program attribute to set to 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 Mode 这篇关于带有GO的Visual Studio代码 - 多个主要声明(启动设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
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 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.# directory/directory/directory/A&B_Directory
./A.go:12:6: main redeclared in this block
previous declaration at ./B.go:18:6
launch.json
file, adding the following sections : {
"name": "Launch Program",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "FullDirectory/A.go"
}
${file}
and many other variations that failed.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
}
]
}
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
.