Use the iota keyword inside a const block to automatically generate sequential integer values for Go enum constants.
Use iota inside a const block to generate a sequence of integer values for your enum constants. Define the first constant with iota and let subsequent constants in the same block increment automatically.
const (
StatusUnknown Status = iota
StatusActive
StatusInactive
)
This creates StatusUnknown as 0, StatusActive as 1, and StatusInactive as 2.
Go iota patterns create a list of named numbers that count up automatically, starting from zero. They are used to define a fixed set of related options, like different states for a task or types of errors. Think of it like a numbered list where you only write the first number, and the computer fills in the rest.