(in interface{})
| 175 | } |
| 176 | |
| 177 | func InterfaceToInt32Downcast(in interface{}) (int32, bool) { |
| 178 | var ok bool |
| 179 | if in, ok = JSONNumberToIntOrFloat(in); !ok { |
| 180 | return 0, false |
| 181 | } |
| 182 | |
| 183 | switch casted := in.(type) { |
| 184 | case int8: |
| 185 | return int32(casted), true |
| 186 | case int16: |
| 187 | return int32(casted), true |
| 188 | case int32: |
| 189 | return casted, true |
| 190 | case int: |
| 191 | if val := int32(casted); int(val) == casted { |
| 192 | return val, true |
| 193 | } |
| 194 | case int64: |
| 195 | if val := int32(casted); int64(val) == casted { |
| 196 | return val, true |
| 197 | } |
| 198 | case float32: |
| 199 | if val := int32(casted); float32(val) == casted { |
| 200 | return val, true |
| 201 | } |
| 202 | case float64: |
| 203 | if val := int32(casted); float64(val) == casted { |
| 204 | return val, true |
| 205 | } |
| 206 | } |
| 207 | return 0, false |
| 208 | } |
| 209 | |
| 210 | func InterfaceToInt(in interface{}) (int, bool) { |
| 211 | var ok bool |
nothing calls this directly
no test coverage detected