Golang中可以使用iota方便的定义复杂的常量结构,下面是golang spec中的说明
Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants. It is reset to 0 whenever the reserved word const appears in the source and increments after each ConstSpec. It can be used to construct a set of related constants:
示例1
const ( // iota is reset to 0 |
Within an ExpressionList, the value of each iota is the same because it is only incremented after each ConstSpec:
示例2
const ( |
This last example exploits the implicit repetition of the last non-empty expression list.
iota是一个比较有特色的东西,看完这两个例子基本就知道怎么用了,相当于它是一个从0开始自动增加的变量,可以重复使用,可以用来定义单位的大小,比如KB,MB,GB等