MCPcopy Index your code
hub / github.com/cortexlabs/cortex / InterfaceToInt

Function InterfaceToInt

pkg/lib/cast/interface.go:210–231  ·  view source on GitHub ↗
(in interface{})

Source from the content-addressed store, hash-verified

208}
209
210func InterfaceToInt(in interface{}) (int, bool) {
211 var ok bool
212 if in, ok = JSONNumberToInt(in); !ok {
213 return 0, false
214 }
215
216 switch casted := in.(type) {
217 case int8:
218 return int(casted), true
219 case int16:
220 return int(casted), true
221 case int32:
222 return int(casted), true
223 case int:
224 return casted, true
225 case int64:
226 if val := int(casted); int64(val) == casted {
227 return val, true
228 }
229 }
230 return 0, false
231}
232
233func InterfaceToIntDowncast(in interface{}) (int, bool) {
234 var ok bool

Callers 5

IntFunction · 0.92
IntPtrFunction · 0.92
IntListFunction · 0.92
TestInterfaceToIntFunction · 0.85
InterfaceToIntSliceFunction · 0.85

Calls 1

JSONNumberToIntFunction · 0.85

Tested by 1

TestInterfaceToIntFunction · 0.68