ENUM in Go
Ha, sike! Go doesn’t have an enum primitive as part of the language!! This is one common gripe about the language.
There are a few patterns that you can utilize to get similar behavior to enum. For example:
- Using
iota
constants + an interface to restrict an argument to an “enum” — example go-enum
lib- This guy wrote a really long blog post/repo on the topic
Last modified: