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

Function InterfaceToIntDowncast

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

Source from the content-addressed store, hash-verified

231}
232
233func InterfaceToIntDowncast(in interface{}) (int, bool) {
234 var ok bool
235 if in, ok = JSONNumberToIntOrFloat(in); !ok {
236 return 0, false
237 }
238
239 switch casted := in.(type) {
240 case int8:
241 return int(casted), true
242 case int16:
243 return int(casted), true
244 case int32:
245 return int(casted), true
246 case int:
247 return casted, true
248 case int64:
249 if val := int(casted); int64(val) == casted {
250 return val, true
251 }
252 case float32:
253 if val := int(casted); float32(val) == casted {
254 return val, true
255 }
256 case float64:
257 if val := int(casted); float64(val) == casted {
258 return val, true
259 }
260 }
261 return 0, false
262}
263
264func InterfaceToInt64(in interface{}) (int64, bool) {
265 var ok bool

Callers 1

Calls 1

JSONNumberToIntOrFloatFunction · 0.85

Tested by 1