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

Function InterfaceToInt8

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

Source from the content-addressed store, hash-verified

22)
23
24func InterfaceToInt8(in interface{}) (int8, bool) {
25 var ok bool
26 if in, ok = JSONNumberToInt(in); !ok {
27 return 0, false
28 }
29
30 switch casted := in.(type) {
31 case int8:
32 return casted, true
33 case int16:
34 if val := int8(casted); int16(val) == casted {
35 return val, true
36 }
37 case int32:
38 if val := int8(casted); int32(val) == casted {
39 return val, true
40 }
41 case int:
42 if val := int8(casted); int(val) == casted {
43 return val, true
44 }
45 case int64:
46 if val := int8(casted); int64(val) == casted {
47 return val, true
48 }
49 }
50 return 0, false
51}
52
53func InterfaceToInt8Downcast(in interface{}) (int8, bool) {
54 var ok bool

Callers 1

TestInterfaceToInt8Function · 0.85

Calls 1

JSONNumberToIntFunction · 0.85

Tested by 1

TestInterfaceToInt8Function · 0.68