Documentation ¶
Index ¶
- Variables
- type Enum
- func (e Enum) ConstName(value string) Snippet
- func (e Enum) ConstUnknown() Snippet
- func (e Enum) ConstValues(f *File) Snippet
- func (e Enum) Errors(f *File) Snippet
- func (e Enum) Integer(f *File) Snippet
- func (e Enum) LabelParser(f *File) Snippet
- func (e Enum) Labeler(f *File) Snippet
- func (e Enum) Receiver(name string) *SnippetField
- func (e Enum) Scanner(f *File) Snippet
- func (e Enum) StarReceiver(name string) *SnippetField
- func (e Enum) StringParser(f *File) Snippet
- func (e Enum) Stringer(f *File) Snippet
- func (e Enum) TextMarshaler(f *File) Snippet
- func (e Enum) TextUnmarshaler(f *File) Snippet
- func (e Enum) TypeName(f *File) Snippet
- func (e Enum) Valuer(f *File) Snippet
- func (e Enum) VarInvalidError() Snippet
- func (e Enum) WriteToFile(f *File)
- type Generator
- type Option
- type Options
- type Scanner
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( PkgPath string IntStringerName = "IntStringerEnum" ValueOffsetName = "ValueOffset" ScanIntEnumStringerName = "ScanIntEnumStringer" )
Functions ¶
This section is empty.
Types ¶
type Enum ¶
func GetEnumByName ¶
func (Enum) ConstName ¶
Example ¶
fmt.Println(string(sample.ConstName("XXX").Bytes())) fmt.Println(string(sample.ConstName("ABC").Bytes())) fmt.Println(string(scheme.ConstName("HTTP").Bytes())) fmt.Println(string(scheme.ConstName("HTTPS").Bytes()))
Output: SAMPLE__XXX SAMPLE__ABC SCHEME__HTTP SCHEME__HTTPS
func (Enum) ConstUnknown ¶
func (e Enum) ConstUnknown() Snippet
func (Enum) ConstValues ¶
func (e Enum) ConstValues(f *File) Snippet
Example ¶
fmt.Println(string(sample.ConstValues(f).Bytes()))
Output: func (v Sample) ConstValues() []enum.IntStringerEnum { return []enum.IntStringerEnum{SAMPLE__XXX, SAMPLE__YYY, SAMPLE__ZZZ} }
func (Enum) Errors ¶
func (e Enum) Errors(f *File) Snippet
Example ¶
fmt.Println(string(sample.Errors(f).Bytes())) fmt.Println(string(scheme.Errors(f).Bytes()))
Output: var InvalidSample = errors.New("invalid Sample type") var InvalidScheme = errors.New("invalid Scheme type")
func (Enum) Integer ¶
func (e Enum) Integer(f *File) Snippet
Example ¶
fmt.Println(string(sample.Integer(f).Bytes()))
Output: func (v Sample) Int() int { return int(v) }
func (Enum) LabelParser ¶
func (e Enum) LabelParser(f *File) Snippet
Example ¶
fmt.Println(string(sample.LabelParser(f).Bytes()))
Output: func ParseSampleFromLabel(s string) (Sample, error) { switch s { default: return SAMPLE_UNKNOWN, InvalidSample case "": return SAMPLE_UNKNOWN, nil case "样例XXX": return SAMPLE__XXX, nil case "样例YYY": return SAMPLE__YYY, nil case "样例ZZZ": return SAMPLE__ZZZ, nil } }
func (Enum) Labeler ¶
func (e Enum) Labeler(f *File) Snippet
Example ¶
fmt.Println(string(sample.Labeler(f).Bytes()))
Output: func (v Sample) Label() string { switch v { default: return "UNKNOWN" case SAMPLE_UNKNOWN: return "" case SAMPLE__XXX: return "样例XXX" case SAMPLE__YYY: return "样例YYY" case SAMPLE__ZZZ: return "样例ZZZ" } }
func (Enum) Scanner ¶
func (e Enum) Scanner(f *File) Snippet
Example ¶
fmt.Println(string(sample.Scanner(f).Bytes()))
Output: func (v *Sample) Scan(src interface{}) error { offset := 0 o, ok := interface{}(v).(enum.ValueOffset) if ok { offset = o.Offset() } i, err := enum.ScanIntEnumStringer(src, offset) if err != nil { return err } *(v) = Sample(i) return nil }
func (Enum) StarReceiver ¶
func (Enum) StringParser ¶
func (e Enum) StringParser(f *File) Snippet
Example ¶
fmt.Println(string(sample.StringParser(f).Bytes()))
Output: func ParseSampleFromString(s string) (Sample, error) { switch s { default: return SAMPLE_UNKNOWN, InvalidSample case "": return SAMPLE_UNKNOWN, nil case "XXX": return SAMPLE__XXX, nil case "YYY": return SAMPLE__YYY, nil case "ZZZ": return SAMPLE__ZZZ, nil } }
func (Enum) Stringer ¶
func (e Enum) Stringer(f *File) Snippet
Example ¶
fmt.Println(string(sample.Stringer(f).Bytes()))
Output: func (v Sample) String() string { switch v { default: return "UNKNOWN" case SAMPLE_UNKNOWN: return "" case SAMPLE__XXX: return "XXX" case SAMPLE__YYY: return "YYY" case SAMPLE__ZZZ: return "ZZZ" } }
func (Enum) TextMarshaler ¶
func (e Enum) TextMarshaler(f *File) Snippet
Example ¶
fmt.Println(string(sample.TextMarshaler(f).Bytes()))
Output: func (v Sample) MarshalText() ([]byte, error) { s := v.String() if s == "UNKNOWN" { return nil, InvalidSample } return []byte(s), nil }
func (Enum) TextUnmarshaler ¶
func (e Enum) TextUnmarshaler(f *File) Snippet
Example ¶
fmt.Println(string(sample.TextUnmarshaler(f).Bytes()))
Output: func (v *Sample) UnmarshalText(data []byte) error { s := string(bytes.ToUpper(data)) val, err := ParseSampleFromString(s) if err != nil { return err } *(v) = val return nil }
func (Enum) Valuer ¶
func (e Enum) Valuer(f *File) Snippet
Example ¶
fmt.Println(string(sample.Valuer(f).Bytes()))
Output: func (v Sample) Value() (driver.Value, error) { offset := 0 o, ok := interface{}(v).(enum.ValueOffset) if ok { offset = o.Offset() } return int64(v) + int64(offset), nil }
func (Enum) VarInvalidError ¶
func (e Enum) VarInvalidError() Snippet
func (Enum) WriteToFile ¶
func (e Enum) WriteToFile(f *File)
type Option ¶
type Option struct { Label string `json:"label"` Str *string `json:"str,omitempty"` Int *int64 `json:"int,omitempty"` Float *float64 `json:"float,omitempty"` }
func NewFloatOption ¶
func NewIntOption ¶
func NewStringOption ¶
Click to show internal directories.
Click to hide internal directories.