null

package
v1.16.11 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: BSD-2-Clause-Patent Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	sql.NullBool
}

Bool is a nullable bool. It does not consider false values to be null. It will decode to null, not false, if null.

func (Bool) IsZero

func (b Bool) IsZero() bool

IsZero returns true for invalid Bools, for future omitempty support (Go 1.4?). A non-null Bool with a 0 value will not be considered zero.

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Bool. It also supports unmarshalling a sql.NullBool.

type Int

type Int struct {
	sql.NullInt64
}

Int is an nullable int64. It does not consider zero values to be null. It will decode to null, not zero, if null.

func (Int) IsZero

func (i Int) IsZero() bool

IsZero returns true for invalid Ints, for future omitempty support (Go 1.4?). A non-null Int with a 0 value will not be considered zero.

func (*Int) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will not be considered a null Int. It also supports unmarshalling a sql.NullInt64.

type String

type String struct {
	sql.NullString
}

String is a nullable string. It supports SQL and JSON serialization. It will marshal to null if null. Blank string input will be considered null.

func (String) IsZero

func (s String) IsZero() bool

IsZero returns true for null strings, for potential future omitempty support.

func (*String) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input does not produce a null String. It also supports unmarshalling a sql.NullString.

type Time

type Time struct {
	Time  time.Time
	Valid bool
}

Time is a nullable time.Time. JSON marshals to the zero value for time.Time if null. Considered to be null to SQL if zero.

func NewTime

func NewTime(t time.Time, valid bool) Time

NewTime creates a new Time.

func TimeFrom

func TimeFrom(t time.Time) Time

TimeFrom creates a new Time that will always be valid.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero returns true for null or zero Times, for potential future omitempty support.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this time is null.

func (Time) Ptr

func (t Time) Ptr() *time.Time

Ptr returns a pointer to this Time's value, or a nil pointer if this Time is zero.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler. It supports string, object (e.g. pq.NullTime and friends) and null input.

func (Time) ValueOrZero

func (t Time) ValueOrZero() time.Time

ValueOrZero returns the inner value if valid, otherwise zero.

Jump to

Keyboard shortcuts

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