-
Notifications
You must be signed in to change notification settings - Fork 0
/
auto_wire_ag.go
143 lines (121 loc) · 3.08 KB
/
auto_wire_ag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Code generated by https://github.com/expgo/ag DO NOT EDIT.
// Plugins:
// - github.com/expgo/enum
package factory
import (
"errors"
"fmt"
"strings"
)
const (
// TagWire is a Tag of type wire.
TagWire Tag = "wire"
// TagValue is a Tag of type value.
TagValue Tag = "value"
// TagNew is a Tag of type new.
TagNew Tag = "new"
)
const (
WireValueSelf WireValue = "self"
WireValueAuto WireValue = "auto"
WireValueType WireValue = "type"
WireValueName WireValue = "name"
WireValueValue WireValue = "value"
)
var ErrInvalidTag = errors.New("not a valid Tag")
var _TagNameMap = map[string]Tag{
"wire": TagWire,
"value": TagValue,
"new": TagNew,
}
// Name is the attribute of Tag.
func (x Tag) Name() string {
if v, ok := _TagNameMap[string(x)]; ok {
return string(v)
}
return fmt.Sprintf("Tag(%s).Name", string(x))
}
// Val is the attribute of Tag.
func (x Tag) Val() string {
return string(x)
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x Tag) IsValid() bool {
_, ok := _TagNameMap[string(x)]
return ok
}
// String implements the Stringer interface.
func (x Tag) String() string {
return x.Name()
}
// ParseTag converts a string to a Tag.
func ParseTag(value string) (Tag, error) {
if x, ok := _TagNameMap[value]; ok {
return x, nil
}
return "", fmt.Errorf("%s is %w", value, ErrInvalidTag)
}
var ErrInvalidWireValue = errors.New("not a valid WireValue")
var _WireValueNameMap = map[string]WireValue{
"self": WireValueSelf,
"auto": WireValueAuto,
"type": WireValueType,
"name": WireValueName,
"value": WireValueValue,
}
// Name is the attribute of WireValue.
func (x WireValue) Name() string {
if v, ok := _WireValueNameMap[string(x)]; ok {
return string(v)
}
return fmt.Sprintf("WireValue(%s).Name", string(x))
}
// Val is the attribute of WireValue.
func (x WireValue) Val() string {
return string(x)
}
var _WireValueValues = []WireValue{
WireValueSelf,
WireValueAuto,
WireValueType,
WireValueName,
WireValueValue,
}
// WireValueValues returns a list of the values of WireValue
func WireValueValues() []WireValue {
return _WireValueValues
}
// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x WireValue) IsValid() bool {
_, ok := _WireValueNameMap[string(x)]
return ok
}
// String implements the Stringer interface.
func (x WireValue) String() string {
return x.Name()
}
// ParseWireValue converts a string to a WireValue.
func ParseWireValue(value string) (WireValue, error) {
if x, ok := _WireValueNameMap[value]; ok {
return x, nil
}
if x, ok := _WireValueNameMap[strings.ToLower(value)]; ok {
return x, nil
}
return "", fmt.Errorf("%s is %w", value, ErrInvalidWireValue)
}
// MarshalText implements the text marshaller method.
func (x WireValue) MarshalText() ([]byte, error) {
return []byte(x.String()), nil
}
// UnmarshalText implements the text unmarshaller method.
func (x *WireValue) UnmarshalText(text []byte) error {
val, err := ParseWireValue(string(text))
if err != nil {
return err
}
*x = val
return nil
}