| 22 | ) |
| 23 | |
| 24 | func 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 | |
| 53 | func InterfaceToInt8Downcast(in interface{}) (int8, bool) { |
| 54 | var ok bool |