-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmargintype_enumer.go
More file actions
100 lines (82 loc) · 2.78 KB
/
Copy pathmargintype_enumer.go
File metadata and controls
100 lines (82 loc) · 2.78 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
// Code generated by "enumer -type MarginType -json -transform snake_upper -trimprefix MarginType"; DO NOT EDIT.
package coinbase
import (
"encoding/json"
"fmt"
"strings"
)
const _MarginTypeName = "UNKNOWN_MARGIN_TYPECROSSISOLATED"
var _MarginTypeIndex = [...]uint8{0, 19, 24, 32}
const _MarginTypeLowerName = "unknown_margin_typecrossisolated"
func (i MarginType) String() string {
if i >= MarginType(len(_MarginTypeIndex)-1) {
return fmt.Sprintf("MarginType(%d)", i)
}
return _MarginTypeName[_MarginTypeIndex[i]:_MarginTypeIndex[i+1]]
}
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
func _MarginTypeNoOp() {
var x [1]struct{}
_ = x[UnknownMarginType-(0)]
_ = x[MarginTypeCross-(1)]
_ = x[MarginTypeIsolated-(2)]
}
var _MarginTypeValues = []MarginType{UnknownMarginType, MarginTypeCross, MarginTypeIsolated}
var _MarginTypeNameToValueMap = map[string]MarginType{
_MarginTypeName[0:19]: UnknownMarginType,
_MarginTypeLowerName[0:19]: UnknownMarginType,
_MarginTypeName[19:24]: MarginTypeCross,
_MarginTypeLowerName[19:24]: MarginTypeCross,
_MarginTypeName[24:32]: MarginTypeIsolated,
_MarginTypeLowerName[24:32]: MarginTypeIsolated,
}
var _MarginTypeNames = []string{
_MarginTypeName[0:19],
_MarginTypeName[19:24],
_MarginTypeName[24:32],
}
// MarginTypeString retrieves an enum value from the enum constants string name.
// Throws an error if the param is not part of the enum.
func MarginTypeString(s string) (MarginType, error) {
if val, ok := _MarginTypeNameToValueMap[s]; ok {
return val, nil
}
if val, ok := _MarginTypeNameToValueMap[strings.ToLower(s)]; ok {
return val, nil
}
return 0, fmt.Errorf("%s does not belong to MarginType values", s)
}
// MarginTypeValues returns all values of the enum
func MarginTypeValues() []MarginType {
return _MarginTypeValues
}
// MarginTypeStrings returns a slice of all String values of the enum
func MarginTypeStrings() []string {
strs := make([]string, len(_MarginTypeNames))
copy(strs, _MarginTypeNames)
return strs
}
// IsAMarginType returns "true" if the value is listed in the enum definition. "false" otherwise
func (i MarginType) IsAMarginType() bool {
for _, v := range _MarginTypeValues {
if i == v {
return true
}
}
return false
}
// MarshalJSON implements the json.Marshaler interface for MarginType
func (i MarginType) MarshalJSON() ([]byte, error) {
return json.Marshal(i.String())
}
// UnmarshalJSON implements the json.Unmarshaler interface for MarginType
func (i *MarginType) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("MarginType should be a string, got %s", data)
}
var err error
*i, err = MarginTypeString(s)
return err
}