MCPcopy
hub / github.com/bitly/go-simplejson / Int

Method Int

simplejson_reader.go:44–57  ·  view source on GitHub ↗

Int coerces into an int

()

Source from the content-addressed store, hash-verified

42
43// Int coerces into an int
44func (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
60func (j *Json) Int64() (int64, error) {

Callers 5

MustIntMethod · 0.95
TestSimplejsonFunction · 0.80
Float64Method · 0.80
Int64Method · 0.80
Uint64Method · 0.80

Calls 1

Int64Method · 0.80

Tested by 1

TestSimplejsonFunction · 0.64