iota is a Go predeclared identifier used inside constant declarations to generate successive integer constants. Start an enumeration with `= iota`; each following line advances the value automatically. section 4.1.2
Pair iota with a named integer-based type to make a small, finite set of values readable and type-safe. The underlying type can remain compact, such as `byte`. section 4.1.2 section 4.6
Logging levels
type Level byte const ( LevelDebug Level = iota LevelInfo LevelError ) The constants receive successive values beginning at zero. Ordering them by importance makes the generated values meaningful; adding another level requires adding another declaration line. section 4.1.2
Word-game hints
type hint byte const ( absentCharacter hint = iota wrongPosition correctPosition ) Using the zero value for the worst status makes the default value useful. A String method can then map each hint to its displayed symbol. section 5.2.1
const (
// LevelDebug represents the lowest level of log, mostly used for
// debugging purposes.
LevelDebug Level = iota
// LevelInfo represents a logging level that contains information
// deemed valuable.
LevelInfo
// LevelError represents the highest logging level, only to be used
// to trace errors.
LevelError
)
Inspect the complete typed enumeration for logging levels, including documentation comments and successive declarations. section 4.1.2
Listing 5.22 hint.go: Hint character type and enum
// hint describes the validity of a character in a word.
type hint byte
const (
absentCharacter hint = iota #1
wrongPosition #2
correctPosition #3
)
Inspect the hint enumeration used to represent absent, misplaced, and correct characters. section 5.2.1
