运行文件夹时进行调试

huangapple go评论83阅读模式
英文:

Debug when run a folder

问题

我有一个名为cmd的文件夹。
当我想运行我的程序时,我需要运行以下命令:
go run cmd/*.go server,其中server是一个参数。

但是我不知道如何在VsCode中设置我的程序的调试。
我尝试了以下配置,但都不起作用。

{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/main.go cmd/initialize.go cmd/commands.go cmd/pubsub_action.go", // cmd目录中的所有go文件
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}
{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/*go",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}
{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/*",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}

问题是,运行我的应用程序的调试的正确方法是什么?

英文:

I have a folder called cmd.
When I want to run my program, I need to run the command.
go run cmd/*.go server where server is an argument.

But I don't know how to setup the debugging for my program in VsCode.
I have tried these configurations but none of these works.

{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/main.go cmd/initialize.go cmd/commands.go cmd/pubsub_action.go", // all go files in the cmd directory
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}
{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/*go",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}
{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd/*",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}

The question is, what is the correct way to run debugging for my application?

答案1

得分: 1

找到了解决方案。

{
  "name": "启动包测试",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}

将程序设置为 cmd

英文:

Found the solution.

{
  "name": "Launch Package Test",
  "type": "go",
  "request": "launch",
  "mode": "auto",
  "program": "cmd",
  "cwd": "${workspace}",
  "args": [
    "server"
  ]
}

Set the program to cmd

huangapple
  • 本文由 发表于 2022年4月10日 12:32:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/71813775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定