-
Notifications
You must be signed in to change notification settings - Fork 1
/
level_enumer.go
131 lines (107 loc) · 2.98 KB
/
level_enumer.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
// Code generated by "enumer -type=Level -json -text -yaml -sql"; DO NOT EDIT.
package tracer
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
const _LevelName = "NO_TRACEAPPLICATION_TRACEMODEL_TRACEFRAMEWORK_TRACEML_LIBRARY_TRACESYSTEM_LIBRARY_TRACEHARDWARE_TRACEFULL_TRACE"
var _LevelIndex = [...]uint8{0, 8, 25, 36, 51, 67, 87, 101, 111}
func (i Level) String() string {
if i < 0 || i >= Level(len(_LevelIndex)-1) {
return fmt.Sprintf("Level(%d)", i)
}
return _LevelName[_LevelIndex[i]:_LevelIndex[i+1]]
}
var _LevelValues = []Level{0, 1, 2, 3, 4, 5, 6, 7}
var _LevelNameToValueMap = map[string]Level{
_LevelName[0:8]: 0,
_LevelName[8:25]: 1,
_LevelName[25:36]: 2,
_LevelName[36:51]: 3,
_LevelName[51:67]: 4,
_LevelName[67:87]: 5,
_LevelName[87:101]: 6,
_LevelName[101:111]: 7,
}
// LevelString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func LevelString(s string) (Level, error) {
if val, ok := _LevelNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to Level values", s)
}
// LevelValues returns all values of the enum
func LevelValues() []Level {
return _LevelValues
}
// IsALevel returns "true" if the value is listed in the enum definition. "false" otherwise
func (i Level) IsALevel() bool {
for _, v := range _LevelValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for Level
func (i Level) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for Level
func (i *Level) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("Level should be a string, got %s", data)
}
var err error
*i, err = LevelString(s)
return err
}
// MarshalText implements the encoding.TextMarshaler interface for Level
func (i Level) MarshalText() ([]byte, error) {
return []byte(i.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface for Level
func (i *Level) UnmarshalText(text []byte) error {
var err error
*i, err = LevelString(string(text))
return err
}
// MarshalYAML implements a YAML Marshaler for Level
func (i Level) MarshalYAML() (interface{}, error) {
return i.String(), nil
}
// UnmarshalYAML implements a YAML Unmarshaler for Level
func (i *Level) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
}
var err error
*i, err = LevelString(s)
return err
}
func (i Level) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *Level) Scan(value interface{}) error {
if value == nil {
return nil
}
str, ok := value.(string)
if !ok {
bytes, ok := value.([]byte)
if !ok {
return fmt.Errorf("value is not a byte slice")
}
str = string(bytes[:])
}
val, err := LevelString(str)
if err != nil {
return err
}
*i = val
return nil
}