Documentation
¶
Index ¶
- type Options
- func (op *Options) MinimizeIntegerSize() bool
- func (op *Options) SetMinimizeIntegerSize(min bool) *Options
- func (op *Options) SetStructName(name string) *Options
- func (op *Options) SetTruncateIntegers(truncate bool) *Options
- func (op *Options) StructName() string
- func (op *Options) TruncateIntegers() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options defines internal struct for options
func (*Options) MinimizeIntegerSize ¶
MinimizeIntegerSize is a getter for minimizeIntegerSize value
func (*Options) SetMinimizeIntegerSize ¶
SetMinimizeIntegerSize specifies how JSON numbers should be represented in Go types.
If false, numbers in JSON input will always be represented as float64 in structs.
If true, JSON numbers will be represented using either int32, int64, float32, or float64. For example, the JSON field "x: 100" would be converted to the struct field "X int32" while "x: 2^32 + 10" would be converted to "X int64" because (2^32 + 10) overflows int32.
The default is true.
func (*Options) SetStructName ¶
SetStructName specifies the name of the generated struct. The default value is "AutoGenerated".
func (*Options) SetTruncateIntegers ¶
SetTruncateIntegers specifies whether or not integer fields in generated structs should have the "truncate" BSON struct tag. This tag enables non-integer data to be decoded into the integer field at the risk of loss of precision.
For example, if this option is true and SetMinimizeIntegerSize is true, the JSON field "x: 1.0" would be converted to struct field "X int32 `bson:"x,truncate"`", which would allow data like "x: 5.4" to be decoded into the struct.
This option is a no-op if SetMinimizeIntegerSize(false) is also called because in that case, all numeric JSON fields are converted to float64 and the "truncate" tag is not meaningful for that type.
The default value is false.
func (*Options) StructName ¶
StructName is a getter for structName value
func (*Options) TruncateIntegers ¶
TruncateIntegers is a getter for trucateIntegers value