What is an idiomatic way of representing enums in Go?

Technology CommunityCategory: GolangWhat is an idiomatic way of representing enums in Go?
VietMX Staff asked 3 years ago

Use Iota. 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:

const (
        A = iota
        C
        T
        G
)

or

type Base int

const (
        A Base = iota
        C
        T
        G
)