| 231 | } |
| 232 | |
| 233 | func 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 | |
| 264 | func InterfaceToInt64(in interface{}) (int64, bool) { |
| 265 | var ok bool |