Documentation ¶
Overview ¶
Package zero provides a convenient way of handling null values. Types in this package consider empty or zero input the same as null input. Types in this package will encode to their zero value, even if null. Use the null parent package if you don't want this.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
Bool is a nullable bool.
func BoolFromPtr ¶
BoolFromPtr creates a new Bool that be null if b is nil.
func (Bool) IsZero ¶
IsZero returns true for null or zero Bools, for future omitempty support (Go 1.4?)
func (Bool) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Bool is null.
func (Bool) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Bool is null.
func (Bool) Ptr ¶
Ptr returns a poBooler to this Bool's value, or a nil poBooler if this Bool is null.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. "false" will be considered a null Bool. It also supports unmarshalling a sql.NullBool.
func (*Bool) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is a false or not a bool. It will return an error if the input is not a float, blank, or "null".
type Float ¶
type Float struct {
sql.NullFloat64
}
Float is a nullable float64.
func FloatFromPtr ¶
FloatFromPtr creates a new Float that be null if f is nil.
func (Float) IsZero ¶
IsZero returns true for null or zero Floats, for future omitempty support (Go 1.4?)
func (Float) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode null if this Float is null.
func (Float) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Float is null.
func (Float) Ptr ¶
Ptr returns a poFloater to this Float's value, or a nil poFloater if this Float is null.
func (*Float) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Float. It also supports unmarshalling a sql.NullFloat64.
func (*Float) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float if the input is a blank, zero, or not a float. It will return an error if the input is not a float, blank, or "null".
type Int ¶
Int is a nullable int64.
func IntFromPtr ¶
IntFromPtr creates a new Int that be null if i is nil.
func (Int) IsZero ¶
IsZero returns true for null or zero Ints, for future omitempty support (Go 1.4?)
func (Int) MarshalJSON ¶
MarshalJSON implements json.Marshaler. It will encode 0 if this Int is null.
func (Int) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a zero if this Int is null.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports number and null input. 0 will be considered a null Int. It also supports unmarshalling a sql.NullInt64.
func (*Int) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int if the input is a blank, zero, or not an integer. It will return an error if the input is not an integer, blank, or "null".
type String ¶
type String struct {
sql.NullString
}
String is a nullable string.
func StringFrom ¶
StringFrom creates a new String that will be null if s is blank.
func StringFromPtr ¶
StringFromPtr creates a new String that be null if s is nil or blank. It will make s point to the String's value.
func (String) IsZero ¶
IsZero returns true for null or empty strings, for future omitempty support. (Go 1.4?)
func (String) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.
func (String) Ptr ¶
Ptr returns a pointer to this String's value, or a nil pointer if this String is null.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler. It supports string and null input. Blank string input produces a null String. It also supports unmarshalling a sql.NullString.
func (*String) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.