登录
首页 >  Golang >  Go问答

无法设置参数给 Go 应用程序在调试期间

来源:stackoverflow

时间:2024-02-14 14:54:23 261浏览 收藏

在Golang实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《无法设置参数给 Go 应用程序在调试期间》,聊聊,希望可以帮助到正在努力赚钱的你。

问题内容

我正在尝试调试我的 goland 应用程序,但 launch.json 文件存在一些问题。我的应用程序应使用参数运行:my_go_app -c path_to_config。

我的 launch.json 看起来像:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch my go app",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c /home/roman/projects/myapp/some.json"]
        }
    ]
}

但是当我调试应用程序时,我收到以下错误:

提供但未定义标志:-c /home/roman/projects/myapp/some.json /tmp/__debug_bin542579318 的用法: -c 字符串 指定配置文件。 (默认“config.json”)

无需调试,我的应用程序即可成功运行。请解释一下哪里出了问题...


正确答案


我已经找到问题所在了。 json 应该是这样的:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch my go app",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "args": ["-c",  "/home/roman/projects/myapp/some.json"]
        }
    ]
}

到这里,我们也就讲完了《无法设置参数给 Go 应用程序在调试期间》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>