Skip to main content

Go Enum

Go does not have enum. You can simulate using constant integer or string by defining a type. Go's way of simulating enum is similar to TypeScript.

Define Enum

Numeric

type Color int

const ( // iota is reset to 0
Red Color = iota // Red == 0
Yellow
Blue
)

Parse enum from string

Either write it by hand or use code generators. NOTE: I haven't tried any of them yet.

References