options

package
Version: v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

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 NewOptions

func NewOptions() *Options

NewOptions constructs

func (*Options) MinimizeIntegerSize

func (op *Options) MinimizeIntegerSize() bool

MinimizeIntegerSize is a getter for minimizeIntegerSize value

func (*Options) SetMinimizeIntegerSize

func (op *Options) SetMinimizeIntegerSize(min bool) *Options

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

func (op *Options) SetStructName(name string) *Options

SetStructName specifies the name of the generated struct. The default value is "AutoGenerated".

func (*Options) SetTruncateIntegers

func (op *Options) SetTruncateIntegers(truncate bool) *Options

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

func (op *Options) StructName() string

StructName is a getter for structName value

func (*Options) TruncateIntegers

func (op *Options) TruncateIntegers() bool

TruncateIntegers is a getter for trucateIntegers value

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL