Int coerces into an int
()
| 42 | |
| 43 | // Int coerces into an int |
| 44 | func (j *Json) Int() (int, error) { |
| 45 | switch j.data.(type) { |
| 46 | case json.Number: |
| 47 | i, err := j.data.(json.Number).Int64() |
| 48 | return int(i), err |
| 49 | case float32, float64: |
| 50 | return int(reflect.ValueOf(j.data).Float()), nil |
| 51 | case int, int8, int16, int32, int64: |
| 52 | return int(reflect.ValueOf(j.data).Int()), nil |
| 53 | case uint, uint8, uint16, uint32, uint64: |
| 54 | return int(reflect.ValueOf(j.data).Uint()), nil |
| 55 | } |
| 56 | return 0, errors.New("invalid value type") |
| 57 | } |
| 58 | |
| 59 | // Int64 coerces into an int64 |
| 60 | func (j *Json) Int64() (int64, error) { |