The Go enum trick

01-08-20

There is no enum in Go. Some would say we can approximate the functionnality of an enum in different ways, but none of them is perfect.

The simplest way to get something that behaves like an enum is to define some typed constants:

type Planet uint

const (
	Earth EnumType = iota
    Mars
    Neptune
    Saturn
    Uranus
    Mercury
    Pluton
)