cannot unmarshal number <very long number> into Go struct field ... of type int64
zen37 opened this issue · 7 comments
https://ifconfig.co/json returns "ip_decimal":20 digits number
It is translated into int64, it should have been float64 to avoid the error.
Some edits to make it clearer.
Why? It's an integer...
there was no error when changing the data type of the Go struct field from int64 to float64
That doesn't mean it is right? Anyway, closing... nothing to do here. You're free to change it yourself in your program.
GO int64 is 19 digits.
If JSON number is > 19 digits convert to float64, if not leave it as it is now, int64.
The number is only 10 digits long.
The number retrieved in https://ifconfig.co/json is 20 digits long.
It's 10 for me, but I see you just edited your original post to specify 20 digits. Maybe you are using IPv6.
A 64 bit integer has more unique values than a 64 bit float.
Using floats for integer values will be wrong for most users. If you require floats, just change it in your code.