Go enums and iota — Full of tips and tricks with runnable code examples.
- What is an Enum?
- Why do we need enums?
- How can you imitate an enum in Go?
- Creating enum strings automatically
- How to use iota?
- Iota expressions rules with examples
- Iota insights
The problem with the example implementation of String() is that it needs to be kept in sync with the set of values in the enum type.
I don’t know if this was updated after your post, but he does introduce the stringer tool. Which I realize is a little ridiculous as a language tool, but thought I’d point it out.
No, Stringer recommendation was there.
In the post, first I’m trying to explain how enums work rather than the best practices. Then, I widening it more about what to use for enums. Including stringer and iota.