null

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

nolint: dupl

nolint: dupl

nolint: dupl

nolint: dupl

nolint: dupl

nolint: dupl

nolint: dupl

Package null provides performant nullable values for JSON serialization/deserialization

nolint: dupl

nolint: dupl

nolint: dupl

nolint: dupl

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NonEmptyEncoder

func NonEmptyEncoder() jsoniter.ValEncoder

func RegisterValidators

func RegisterValidators(validate *validator.Validate)

RegisterValidators registers custom type validators for null values

func StringDecoder

func StringDecoder() jsoniter.ValDecoder

func StringEncoder

func StringEncoder() jsoniter.ValEncoder

func ValidateNullType

func ValidateNullType(val reflect.Value) interface{}

Types

type Bool

type Bool struct {
	Value  bool
	Exists bool
}

Bool represents a nullable boolean value. It accepts 1, "0", "t", "T", "TRUE", true, "true", "True", 0, "0", "f", "F", "FALSE", false, "false", "False". It is using the same convensions as `stronv.ParseBool` https://golang.org/pkg/strconv/#ParseBool.

func FromBool

func FromBool(b bool) Bool

FromBool creates a non-null Bool. It is inlined by the compiler.

func (*Bool) IsNull

func (b *Bool) IsNull() bool

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Bool value s from string, number or null JSON input using strconv.ParseBool.

type Float32

type Float32 struct {
	Value  float32
	Exists bool
}

func FromFloat32

func FromFloat32(n float32) Float32

FromFloat32 creates a non-null Float32. It is inlined by the compiler.

func (*Float32) IsNull

func (f *Float32) IsNull() bool

func (Float32) MarshalJSON

func (f Float32) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Float32) UnmarshalJSON

func (f *Float32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Float32 value s from string, number or null JSON input.

type Float64

type Float64 struct {
	Value  float64
	Exists bool
}

func FromFloat64

func FromFloat64(n float64) Float64

FromFloat64 creates a non-null Float64. It is inlined by the compiler.

func (*Float64) IsNull

func (f *Float64) IsNull() bool

func (Float64) MarshalJSON

func (f Float64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Float64) UnmarshalJSON

func (f *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Float64 value s from string, number or null JSON input.

type Int16

type Int16 struct {
	Value  int16
	Exists bool
}

Int16 represents a nullable int16 value. It parses both string an number JSON values.

func FromInt16

func FromInt16(n int16) Int16

FromInt16 creates a non-null Int16. It is inlined by the compiler.

func (*Int16) IsNull

func (i *Int16) IsNull() bool

func (Int16) MarshalJSON

func (i Int16) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Int16) UnmarshalJSON

func (i *Int16) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int16 value s from string, number or null JSON input.

type Int32

type Int32 struct {
	Value  int32
	Exists bool
}

Int32 represents a nullable int32 value. It parses both string an number JSON values.

func FromInt32

func FromInt32(n int32) Int32

FromInt32 creates a non-null Int32. It is inlined by the compiler.

func (*Int32) IsNull

func (i *Int32) IsNull() bool

func (Int32) MarshalJSON

func (i Int32) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Int32) UnmarshalJSON

func (i *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int32 value s from string, number or null JSON input.

type Int64

type Int64 struct {
	Value  int64
	Exists bool
}

Int64 represents a nullable int64 value. It parses both string an number JSON values.

func FromInt64

func FromInt64(n int64) Int64

FromInt64 creates a non-null Int64. It is inlined by the compiler.

func (*Int64) IsNull

func (i *Int64) IsNull() bool

func (Int64) MarshalJSON

func (i Int64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Int64) UnmarshalJSON

func (i *Int64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int64 value s from string, number or null JSON input.

type Int8

type Int8 struct {
	Value  int8
	Exists bool
}

Int8 represents a nullable int8 value. It parses both string an number JSON values.

func FromInt8

func FromInt8(n int8) Int8

FromInt8 creates a non-null Int8. It is inlined by the compiler.

func (*Int8) IsNull

func (i *Int8) IsNull() bool

func (Int8) MarshalJSON

func (i Int8) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Int8) UnmarshalJSON

func (i *Int8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int8 value s from string, number or null JSON input.

type NonEmpty

type NonEmpty String

NonEmpty is a nullable string value It's useful to handle string JSON values that could be `null` in the incoming log JSON. It's `omitempty` behavior when used with `jsoniter` is to omit both `""` and `null` in the output

func (*NonEmpty) MarshalJSON

func (s *NonEmpty) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface WARNING: Since `json` package has no method of modifying `omitempty` behavior, the empty values (`null`, `""`) cannot be omitted when using `json.Marshal`. To omit a `null` or empty string we need to use `jsoniter.Marshal`.

func (*NonEmpty) UnmarshalJSON

func (s *NonEmpty) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type String

type String struct {
	Value  string
	Exists bool
}

String is a nullable string value that retains empty string in the input It's useful to handle string JSON values that could be `null` in the incoming log JSON. It's `omitempty` behavior when used with `jsoniter` is to only omit `null` in the output

func FromString

func FromString(s string) String

FromString creates a non-null String. It is inlined by the compiler.

func (*String) IsNull

func (s *String) IsNull() bool

func (*String) MarshalJSON

func (s *String) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*String) String

func (s *String) String() string

func (*String) UnmarshalJSON

func (s *String) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

type Uint16

type Uint16 struct {
	Value  uint16
	Exists bool
}

Uint16 represents a nullable uint16 value. It parses both string an number JSON values.

func FromUint16

func FromUint16(n uint16) Uint16

FromUint16 creates a non-null Uint16. It is inlined by the compiler.

func (*Uint16) IsNull

func (u *Uint16) IsNull() bool

func (Uint16) MarshalJSON

func (u Uint16) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Uint16) UnmarshalJSON

func (u *Uint16) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int16 value s from string, number or null JSON input.

type Uint32

type Uint32 struct {
	Value  uint32
	Exists bool
}

Uint32 represents a nullable uint32 value. It parses both string an number JSON values.

func FromUint32

func FromUint32(n uint32) Uint32

FromUint32 creates a non-null Uint32. It is inlined by the compiler.

func (*Uint32) IsNull

func (u *Uint32) IsNull() bool

func (Uint32) MarshalJSON

func (u Uint32) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Uint32) UnmarshalJSON

func (u *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int32 value s from string, number or null JSON input.

type Uint64

type Uint64 struct {
	Value  uint64
	Exists bool
}

Uint64 represents a nullable uint64 value. It parses both string an number JSON values.

func FromUint64

func FromUint64(n uint64) Uint64

FromUint64 creates a non-null Uint64. It is inlined by the compiler.

func (*Uint64) IsNull

func (u *Uint64) IsNull() bool

func (Uint64) MarshalJSON

func (u Uint64) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Uint64) UnmarshalJSON

func (u *Uint64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int64 value s from string, number or null JSON input.

type Uint8

type Uint8 struct {
	Value  uint8
	Exists bool
}

Uint8 represents a nullable uint8 value. It parses both string an number JSON values.

func FromUint8

func FromUint8(n uint8) Uint8

FromUint8 creates a non-null Uint8. It is inlined by the compiler.

func (*Uint8) IsNull

func (u *Uint8) IsNull() bool

func (Uint8) MarshalJSON

func (u Uint8) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (*Uint8) UnmarshalJSON

func (u *Uint8) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It decodes Int8 value s from string, number or null JSON input.

Jump to

Keyboard shortcuts

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