dpdhsq0783 2017-08-30 12:56
浏览 35
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • doulian8554 2017-08-30 14:23
    关注

    Disclaimer: this is not the recommended approach, I 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态