Documentation ¶
Overview ¶
Package genum provides methods used to generate enum golang type based on CVS data.
Index ¶
- Constants
- func DefaultFormat(valueFormat string) string
- func Generate(opts ...Configurator) (err error)
- func NameFormat() string
- func TypeFormat() string
- type Configurator
- func Layout(s Settings, args []string) []Configurator
- func ParseBitmask(data io.Reader, enumType string, joinPrefix, trimPrefix bool) Configurator
- func ParseEnums(data io.Reader, enumType string, enumKind Kind, ...) Configurator
- func PrintBitmask(enumType string) Configurator
- func PrintEnums(enumType string, useIota, commented bool) Configurator
- func PrintHeader(pkg string, args []string, packages map[string]struct{}) Configurator
- func PrintJSONMarshaler(enumType string, enumKind Kind) Configurator
- func PrintLookup(enumType string, enumKind Kind) Configurator
- func PrintStringer(format string, enumType string, enumKind Kind) Configurator
- func PrintTextMarshaler(format string, enumType string) Configurator
- func PrintValidator(enumType string) Configurator
- func PrintXMLMarshaler(enumType string, enumKind Kind) Configurator
- func WriteFile(filename string) Configurator
- type Enum
- type Generator
- type Kind
- type Pos
- type Settings
Constants ¶
const ( // Command is the name of the command line to generate golang enums based on CSV data. Command = "genum" // DefaultType is the default type name of an enum. DefaultType = "Enum" // DefaultKind is the default base type for an enum. DefaultKind = "int" )
const (
// ErrMissing is returned when a data is missing.
ErrMissing = errGenum("missing data")
)
Variables ¶
This section is empty.
Functions ¶
func DefaultFormat ¶
DefaultFormat returns the format used to return the enum string.
func Generate ¶
func Generate(opts ...Configurator) (err error)
Generate generates the enum file based on these options.
func NameFormat ¶
func NameFormat() string
NameFormat returns the format used to return the enum name.
func TypeFormat ¶
func TypeFormat() string
TypeFormat returns the format used to return the enum type.
Types ¶
type Configurator ¶
Configurator must be implemented by any methods acted as an enum layout generator.
func Layout ¶
func Layout(s Settings, args []string) []Configurator
Layout returns the generation configuration based on the given settings.
func ParseBitmask ¶
func ParseBitmask(data io.Reader, enumType string, joinPrefix, trimPrefix bool) Configurator
ParseBitmask reads the given source as a CSV and tries to create a bitmasks list.
func ParseEnums ¶
func ParseEnums(data io.Reader, enumType string, enumKind Kind, joinPrefix, trimPrefix, useIota bool) Configurator
ParseEnums reads the given source as a CSV and tries to create a list of constants based on it.
func PrintBitmask ¶
func PrintBitmask(enumType string) Configurator
PrintBitmask prints related methods to bitmask operations.
func PrintEnums ¶
func PrintEnums(enumType string, useIota, commented bool) Configurator
PrintEnums prints the list of constants.
func PrintHeader ¶
func PrintHeader(pkg string, args []string, packages map[string]struct{}) Configurator
PrintHeader prints the go file header (package, import, etc.).
func PrintJSONMarshaler ¶
func PrintJSONMarshaler(enumType string, enumKind Kind) Configurator
PrintJSONMarshaler adds methods to marshal and unmarshal the enum value as JSON data.
func PrintLookup ¶
func PrintLookup(enumType string, enumKind Kind) Configurator
PrintLookup adds a private method dedicated to get if exists the name of a constant with ok at true. Otherwise, a standard failover name with ok at false are returned.
func PrintStringer ¶
func PrintStringer(format string, enumType string, enumKind Kind) Configurator
PrintStringer chooses the "best" methods regarding the data to manage the String method.
func PrintTextMarshaler ¶
func PrintTextMarshaler(format string, enumType string) Configurator
PrintTextMarshaler adds methods to marshal and unmarshal the enum String value as a text.
func PrintValidator ¶
func PrintValidator(enumType string) Configurator
PrintValidator builds a method to check the validity of a constant.
func PrintXMLMarshaler ¶
func PrintXMLMarshaler(enumType string, enumKind Kind) Configurator
PrintXMLMarshaler adds methods to marshal and unmarshal the enum value as XML data.
type Enum ¶
Enum represents an Enum.
func (Enum) Format ¶
Format formats the constant regarding to its context (iota, position, etc.)
Enum Kind = iota // e = 0 Enum Enum Kind = iota + 100 _ Kind = iota _ Enum Kind = "rv" Non-exhaustive list.
func (Enum) ParseValue ¶
ParseValue tries to parse the Value as expected by its Kind.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator represents an enum generator.
type Kind ¶
type Kind uint8
Kind represents a golang type.
const ( Int Kind = iota Int8 Int16 Int32 Int64 Uint Uint8 Uint16 Uint32 Uint64 Float32 Float64 String )
List of supported kinds.
func KindUnsigned ¶
KindUnsigned returns an integer unsigned large enough to hold this max value.
func (Kind) ValueFormat ¶
ValueFormat returns the formats used to output a Kind value.
type Settings ¶
type Settings interface { DstFilename() string SrcFile() io.Reader PackageName() string TypeName() string TypeKind() Kind Bitmask() bool Commented() bool JoinPrefix() bool TrimPrefix() bool Validator() bool Iota() bool JSONMarshaler() bool TextMarshaler() bool XMLMarshaler() bool Stringer() bool StringFormater() string }
Settings must be implemented by any service wanted to share generation configuration.