twpayne/go-jsonstruct

using "int" for number types risks overflow

andoks opened this issue ยท 3 comments

andoks commented

I am trying to communicate with an API that returns (and receives) integers may be up to Number.MAX_SAFE_INTEGER. This may overflow if one is compiling on a machine where go decides to use 32bit integers for int.

Could perhaps go-jsonstruct create such fields with int64 type instead?

andoks commented

Maybe this could be done relatively easily by adding a "-inttype" flag, and using WithIntType?

Yup!

$ echo '{"k":1}' | go run ./cmd/gojsonstruct -inttype=int64
package main

type T struct {
        K int64 `json:"k"`
}

I've tagged v2.2.0 which includes this.

andoks commented

Thanks @twpayne! ๐ŸŽ‰ ๐ŸŽ‰ ๐ŸŽ‰

15min turnaround for a new feature must be some kind of record I reckon ๐Ÿ˜