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 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?