This repository was archived by the owner on Sep 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwarncode_enumer.go
More file actions
104 lines (85 loc) · 2.49 KB
/
Copy pathwarncode_enumer.go
File metadata and controls
104 lines (85 loc) · 2.49 KB
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
// Code generated by "enumer -type=WarnCode -json -sql"; DO NOT EDIT.
//
package gmg
import (
"database/sql/driver"
"encoding/json"
"fmt"
)
const _WarnCodeName = "WarnCodeNoneWarnCodeFanOverloadWarnCodeAugerOverloadWarnCodeIgnitorOverloadWarnCodeLowVoltageBatteryWarnCodeFanDisconnectWarnCodeAugerDisconnectWarnCodeIgnitorDisconnectWarnCodeLowPellet"
var _WarnCodeIndex = [...]uint8{0, 12, 31, 52, 75, 100, 121, 144, 169, 186}
func (i WarnCode) String() string {
if i < 0 || i >= WarnCode(len(_WarnCodeIndex)-1) {
return fmt.Sprintf("WarnCode(%d)", i)
}
return _WarnCodeName[_WarnCodeIndex[i]:_WarnCodeIndex[i+1]]
}
var _WarnCodeValues = []WarnCode{0, 1, 2, 3, 4, 5, 6, 7, 8}
var _WarnCodeNameToValueMap = map[string]WarnCode{
_WarnCodeName[0:12]: 0,
_WarnCodeName[12:31]: 1,
_WarnCodeName[31:52]: 2,
_WarnCodeName[52:75]: 3,
_WarnCodeName[75:100]: 4,
_WarnCodeName[100:121]: 5,
_WarnCodeName[121:144]: 6,
_WarnCodeName[144:169]: 7,
_WarnCodeName[169:186]: 8,
}
// WarnCodeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func WarnCodeString(s string) (WarnCode, error) {
if val, ok := _WarnCodeNameToValueMap[s]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to WarnCode values", s)
}
// WarnCodeValues returns all values of the enum
func WarnCodeValues() []WarnCode {
return _WarnCodeValues
}
// IsAWarnCode returns "true" if the value is listed in the enum definition. "false" otherwise
func (i WarnCode) IsAWarnCode() bool {
for _, v := range _WarnCodeValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for WarnCode
func (i WarnCode) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for WarnCode
func (i *WarnCode) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("WarnCode should be a string, got %s", data)
}
var err error
*i, err = WarnCodeString(s)
return err
}
func (i WarnCode) Value() (driver.Value, error) {
return i.String(), nil
}
func (i *WarnCode) 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 := WarnCodeString(str)
if err != nil {
return err
}
*i = val
return nil
}