enum is a tool for generating enum struct
go install github.com/Natata/enum
File format
type:
[int|string]
name:
[package name]
list:
[enum element] = [value]
filename doesn't matter
enum -fp=exam.enum
type:
int
name:
direction
list:
West = 0
east = 1
North = 2
South = 3
result:
package direction
// Alias hide the real type of the enum
// and users can use it to define the var for accepting enum
type Alias = int
type list struct {
West Alias
East Alias
North Alias
South Alias
}
// Enum for public use
var Enum = &list{
West: 0,
East: 1,
North: 2,
South: 3,
}
type:
int
name:
direction
list:
West = 9
east = 8
North = iota
South
result:
package direction
// Alias hide the real type of the enum
// and users can use it to define the var for accepting enum
type Alias = int
type list struct {
West Alias
East Alias
North Alias
South Alias
}
// Enum for public use
var Enum = &list{
West: 9,
East: 8,
North: 0,
South: 1,
}
type:
string
name:
direction
list:
West = "W"
East = "E"
North = "N"
South = "S"
result:
package direction
// Alias hide the real type of the enum
// and users can use it to define the var for accepting enum
type Alias = string
type list struct {
West Alias
East Alias
North Alias
South Alias
}
// Enum for public use
var Enum = &list{
West: "W",
East: "E",
North: "N",
South: "S",
}