Golang Enum

type Base int

const (
        A Base = iota

This code in Go defines a new custom type called Base using the int underlying type.
The const block declares four constant values (A, C, T, G) of type Base using the iota identifier. In Go, iota is a predeclared identifier that represents successive integer constants. When used in a const block, iota starts at 0 and increments by 1 for each subsequent line.
Therefore, in this code, A is assigned the value 0 (since it is the first constant declaration), C is assigned the value 1, T is assigned the value 2, and G is assigned the value 3.

Subscribe for
weekly updates