- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我有一个关于 golangci-lint 的问题。linter 返回我的东西是这样的:
type outputFormat string
const (
formatNone outputFormat = ""
formatText = "TEXT"
formatJSON = "JSON"
)
错误如:
only the first constant in this group has an explicit type (staticcheck)
formatNone outputFormat = ""
但这有什么问题呢?在 https://go101.org/article/constants-and-variables.html他们在常量声明中的自动完成一章中描述了不完整的常量将被识别和填充。
我没有找到任何引用资料告诉我要避免使用不完整的常量定义。
谁能给我解释一下,这是怎么回事?
最佳答案
如 staticcheck 中所述的 documentation for that check :
In a constant declaration such as the following:
const (
First byte = 1
Second = 2
)the constant
Second
does not have the same type as the constantFirst
. This construct shouldn't be confused withconst (
First byte = iota
Second
)where
First
andSecond
do indeed have the same type. The type is only passed on when no explicit value is assigned to the constant.When declaring enumerations with explicit values it is therefore important not to write
const (
EnumFirst EnumType = 1
EnumSecond = 2
EnumThird = 3
)This discrepancy in types can cause various confusing behaviors and bugs.
关于golangci-lint 常量显式类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55282615/
我是一名优秀的程序员,十分优秀!