在表示式中使用 iota

iota 可以在表示式中使用,因此它也可以用於指定除從零開始的簡單遞增整數之外的值。要為 SI 單位建立常量,請使用 Effective Go 中的此示例 :

type ByteSize float64

const (
    _           = iota // ignore first value by assigning to blank identifier
    KB ByteSize = 1 << (10 * iota)
    MB
    GB
    TB
    PB
    EB
    ZB
    YB
)