I am working on an appengine app in Go and when I tried to get an appengine User
's ID and convert it to a 64-bit int with this code:
id, err := strconv.ParseInt(user.ID, 10, 64)
I got this error:
ERROR: error executing inner: strconv.ParseInt: parsing "185804764220139124118": value out of range
Does this error occur on appengine IDs in deployed code as well?
The ID
field of the User
type is defined with type string
. Just because it contains digits, there is no guarantee that it fits into an int64
.
The Go AppengineSDK uses values that fit into int64
, but this is not true in production environment. They are usually longer than the max value of int64
. They are handed to you as string
s, so treat them like that: string
s. Nothing forces you to convert them to a number. I don't know where you got the idea to convert them to numbers, but don't do that. They are string
s.
Note: User.ID
is not to be mistaken with Key.IntID()
which is defined to be of type int64
.
Most probably yes. Reading app engine documentation, it is written that:
The default policy generates a random sequence of unused IDs that are approximately uniformly distributed. Each ID can be up to 16 decimal digits long.
From Go specs int32 is -2147483648 through 2147483647.
which is not enough for 16 decimals, but int64
is enough.