command-line - 默认命令行参数值的编译错误

标签 command-line go default-value

当我尝试使用 uint64 类型的命令行参数时,当我将默认值设置为有效的无符号 64 位数字时,出现以下编译错误。

编译错误: 表达式类型不匹配,预期类型少 uint64 ... 它在此处突出显示数字 5000,表示该值 Not Acceptable 。

代码:

var golferInstance uint64 

flag.Uint64Var(&golferInstance, "inst", 5000, "Golfer Instance ID, this should be Globaly Unique ")
flag.Parse()

我没有看到上面的声明有什么问题,那为什么会编译错误??

我在这里错过了什么? (我相信一定是我没弄明白的傻事) 感谢您的帮助。

谢谢

最佳答案

go-lang-idea-plugin 中的检查类型关于某些类型的不匹配检测有一些问题。
参见 issue 348 (应该在该插件的最新版本中解决)

您可以取消选择该检查器。

In the interface it's called 'Highlight mismatched types', I believe this is the one.
The message from inspection is: 'Expression type mismatch, expected type is ...'

It also seems it has problems in detecting that '1 * time.Second' in the construct 'time.Sleep(1 * time.Second)' is a proper 'Duration' type and it tries to fix it like this 'time.Sleep((time.Duration)(1 * time.Second))'.

回到命令行,和/或确保所有组件都是最新的(golang IntelliJ 插件,Go 本身),可以提供帮助。

关于command-line - 默认命令行参数值的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26942654/

相关文章:

c++ - 从命令行 Python/C++ 启动 Minecraft

c++ - 从 C++ 应用程序运行系统命令不同于命令行

go - 第三方库 (mgo.v2) 供应错误

c# - 如何在 ASP.NET 中为自动实现的属性设置默认值

ios - Xamarin.iOS 中未加载设置包中的默认值

ubuntu - (警告) Ubuntu-Server 重叠和更早的别名

git - 如何使用命令行 git 从 Github 接受 pull 请求 (PR)

pointers - 您可以将多个值中的部分或全部作为函数的指针返回吗?

go - 将 CSV 解码为 Struct 然后导入

带有扩展参数和默认参数的 TypeScript 泛型约束