| 51 | } |
| 52 | |
| 53 | func InterfaceToInt8Downcast(in interface{}) (int8, bool) { |
| 54 | var ok bool |
| 55 | if in, ok = JSONNumberToIntOrFloat(in); !ok { |
| 56 | return 0, false |
| 57 | } |
| 58 | |
| 59 | switch casted := in.(type) { |
| 60 | case int8: |
| 61 | return casted, true |
| 62 | case int16: |
| 63 | if val := int8(casted); int16(val) == casted { |
| 64 | return val, true |
| 65 | } |
| 66 | case int32: |
| 67 | if val := int8(casted); int32(val) == casted { |
| 68 | return val, true |
| 69 | } |
| 70 | case int: |
| 71 | if val := int8(casted); int(val) == casted { |
| 72 | return val, true |
| 73 | } |
| 74 | case int64: |
| 75 | if val := int8(casted); int64(val) == casted { |
| 76 | return val, true |
| 77 | } |
| 78 | case float32: |
| 79 | if val := int8(casted); float32(val) == casted { |
| 80 | return val, true |
| 81 | } |
| 82 | case float64: |
| 83 | if val := int8(casted); float64(val) == casted { |
| 84 | return val, true |
| 85 | } |
| 86 | } |
| 87 | return 0, false |
| 88 | } |
| 89 | |
| 90 | func InterfaceToInt16(in interface{}) (int16, bool) { |
| 91 | var ok bool |