Go has no enum keyword; a golang enum is usually a named integer type plus const values, often driven by iota. That gives compile-time distinct values, optional String() for logging, and small helpers to validate or parse wire strings. For structured data, pair enums with structs and JSON rules that match your API.
Tested with Go 1.24 on Linux.
Basic iota enum
package main
import "fmt"
type Weekday int
const (
Sunday Weekday = iota
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
)
func main() {
fmt.Println(int(Sunday), int(Saturday))
}You should see 0 and 6.
Names and String()
Implement String() with a switch statement in Go so fmt and logs print friendly names; that method satisfies fmt.Stringer the same way as in interfaces in Go.
package main
import "fmt"
type Status int
const (
StatusUnknown Status = iota
StatusOK
StatusFailed
)
func (s Status) String() string {
switch s {
case StatusOK:
return "OK"
case StatusFailed:
return "FAILED"
default:
return "UNKNOWN"
}
}
func main() {
var st Status = StatusOK
fmt.Println(st.String())
}You should see OK.
Parsing strings (API boundary)
package main
import "fmt"
type Tier int
const (
TierFree Tier = iota
TierPro
)
func ParseTier(s string) (Tier, bool) {
switch s {
case "free":
return TierFree, true
case "pro":
return TierPro, true
default:
return TierFree, false
}
}
func main() {
fmt.Println(ParseTier("pro"))
}You should see 1 and true.
Summary
A golang enum is idiomatically a typed const block with iota, sometimes with gaps for stable IDs. Add String(), parse helpers, and JSON mapping at the edges where text meets your domain.
References
Frequently Asked Questions
Does Go have an enum keyword?
No. Use typed constants with iota or separate const blocks for disjoint sets.
What is iota?
A predeclared counter that starts at zero in each const block and increments for each const specifier, handy for sequential numeric enums.
How do I print friendly enum names?
Implement fmt.Stringer on the named type or switch on the value in a helper.
How do I accept enums from JSON strings?
Unmarshal into string then map with a switch or map[string]YourType, or implement UnmarshalJSON on the named type.
Can I skip iota values?
Yes, use explicit assignments or _ placeholders to leave gaps when you need stable wire values.

