is there a simple implementation of enums in golang? Something like the following?
type status enum[string] {
pending = "PENDING"
active = "ACTIVE"
}
is there a simple implementation of enums in golang? Something like the following?
type status enum[string] {
pending = "PENDING"
active = "ACTIVE"
}
const (
statusPending = "PENDING"
statusActive = "ACTIVE"
)
Or, application of the example at Ultimate Visual Guide to Go Enums
// Declare a new type named status which will unify our enum values
// It has an underlying type of unsigned integer (uint).
type status int
// Declare typed constants each with type of status
const (
pending status = iota
active
)
// String returns the string value of the status
func (s status) String() string {
strings := [...]string{"PENDING", "ACTIVE"}
// prevent panicking in case of status is out-of-range
if s < pending || s > active {
return "Unknown"
}
return strings[s]
}
Something like the following?
Not yet
Read here What is an idiomatic way of representing enums in Go?