-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathor.go
199 lines (177 loc) · 4.41 KB
/
or.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package any
// Or sets the Value to the default when not Ok and returns the Value.
// Otherwise, the original Value is returned and the default is ignored.
// This is useful for providing a default before using the underlying value.
func (v Value) Or(i interface{}) Value {
if !v.Ok() {
v.i = i
}
return v
}
// BoolOr returns the value as a bool type or the default when the Value is not of type bool
func (v Value) BoolOr(d bool) bool {
b, ok := v.i.(bool)
if !ok {
return d
}
return b
}
// IntOr returns the value as a int type or the default when the Value is not of type int.
func (v Value) IntOr(d int) int {
i, ok := v.i.(int)
if !ok {
return d
}
return i
}
// Int8Or returns the value as a int8 type or the default when the Value is not of type int8.
func (v Value) Int8Or(d int8) int8 {
i, ok := v.i.(int8)
if !ok {
return d
}
return i
}
// Int16Or returns the value as a int16 type or the default when the Value is not of type int16.
func (v Value) Int16Or(d int16) int16 {
i, ok := v.i.(int16)
if !ok {
return d
}
return i
}
// Int32Or returns the value as a int32 type or the default when the Value is not of type int32.
func (v Value) Int32Or(d int32) int32 {
i, ok := v.i.(int32)
if !ok {
return d
}
return i
}
// Int64Or returns the value as a int64 type or the default when the Value is not of type int64.
func (v Value) Int64Or(d int64) int64 {
i, ok := v.i.(int64)
if !ok {
return d
}
return i
}
// UintOr returns the value as a uint type or the default when the Value is not of type uint.
func (v Value) UintOr(d uint) uint {
i, ok := v.i.(uint)
if !ok {
return d
}
return i
}
// Uint8Or returns the value as a uint8 type or the default when the Value is not of type uint8.
func (v Value) Uint8Or(d uint8) uint8 {
i, ok := v.i.(uint8)
if !ok {
return d
}
return i
}
// Uint16Or returns the value as a uint16 type or the default when the Value is not of type uint16.
func (v Value) Uint16Or(d uint16) uint16 {
i, ok := v.i.(uint16)
if !ok {
return d
}
return i
}
// Uint32Or returns the value as a uint32 type or the default when the Value is not of type uint32.
func (v Value) Uint32Or(d uint32) uint32 {
i, ok := v.i.(uint32)
if !ok {
return d
}
return i
}
// Uint64Or returns the value as a uint64 type or the default when the Value is not of type uint64.
func (v Value) Uint64Or(d uint64) uint64 {
i, ok := v.i.(uint64)
if !ok {
return d
}
return i
}
// UintptrOr returns the value as a uintptr type or the default when the Value is not of type uintptr.
func (v Value) UintptrOr(d uintptr) uintptr {
i, ok := v.i.(uintptr)
if !ok {
return d
}
return i
}
// Float32Or returns the value as a float32 type or the default when the Value is not of type float32.
func (v Value) Float32Or(d float32) float32 {
f, ok := v.i.(float32)
if !ok {
return d
}
return f
}
// Float64Or returns the value as a float64 type or the default when the Value is not of type float64.
func (v Value) Float64Or(d float64) float64 {
f, ok := v.i.(float64)
if !ok {
return d
}
return f
}
// Complex64Or returns the value as a complex64 type or the default when the Value is not of type complex64.
func (v Value) Complex64Or(d complex64) complex64 {
c, ok := v.i.(complex64)
if !ok {
return d
}
return c
}
// Complex128Or returns the value as a complex128 type or the default when the Value is not of type complex128.
func (v Value) Complex128Or(d complex128) complex128 {
c, ok := v.i.(complex128)
if !ok {
return d
}
return c
}
// ByteOr returns the value as a byte type or the default when the Value is not of type byte.
func (v Value) ByteOr(d byte) byte {
b, ok := v.i.(byte)
if !ok {
return d
}
return b
}
// BytesOr returns the value as a []byte type or the default when the Value is not of type []byte.
func (v Value) BytesOr(d []byte) []byte {
b, ok := v.i.([]byte)
if !ok {
return d
}
return b
}
// RuneOr returns the value as a rune type or the default when the Value is not of type rune.
func (v Value) RuneOr(d rune) rune {
r, ok := v.i.(rune)
if !ok {
return d
}
return r
}
// StringOr returns the value as a string type or the default when the Value is not of type string.
func (v Value) StringOr(d string) string {
s, ok := v.i.(string)
if !ok {
return d
}
return s
}
// InterfaceOr provides the underlying value as an empty interface or the default when not Ok.
func (v Value) InterfaceOr(d interface{}) interface{} {
if !v.Ok() {
return d
}
return v.i
}