null

package
v0.0.0-...-edb78a7 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2015 License: GPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package null contains types that consider zero input and null input as separate values. Types in this package will always encode to their null value if null. Use the zero subpackage if you want empty and null to be treated the same.

Index

Constants

View Source
const (
	DDMMYYYY = "02/01/2006"
)
View Source
const (
	DDMMYYYYHHMMSS = "02/01/2006 15:04:05"
)

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 BoolFrom

func BoolFrom(b bool) Bool

BoolFrom creates a new Bool that will always be valid.

func BoolFromPtr

func BoolFromPtr(b *bool) Bool

BoolFromPtr creates a new Bool that will be null if f is nil.

func NewBool

func NewBool(b bool, valid bool) Bool

NewBool creates a new Bool

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) MarshalJSON

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

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

func (Bool) MarshalText

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

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Bool is null.

func (Bool) Ptr

func (b Bool) Ptr() *bool

Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.

func (*Bool) SetValid

func (b *Bool) SetValid(v bool)

SetValid changes this Bool's value and also sets it to be non-null.

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.

func (*Bool) UnmarshalText

func (b *Bool) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Bool if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

type Date

type Date struct {
	Date  time.Time
	Valid bool
}

func NewDate

func NewDate(date time.Time) Date

func (*Date) After

func (d *Date) After(that *Date) bool

func (*Date) Before

func (d *Date) Before(that *Date) bool

func (*Date) Equal

func (d *Date) Equal(that *Date) bool

func (Date) IsZero

func (d Date) IsZero() bool

func (Date) MarshalJSON

func (n Date) MarshalJSON() ([]byte, error)

func (Date) MarshalText

func (n Date) MarshalText() ([]byte, error)

func (*Date) Scan

func (n *Date) Scan(value interface{}) error

func (*Date) UnmarshalJSON

func (n *Date) UnmarshalJSON(data []byte) (err error)

func (*Date) UnmarshalText

func (n *Date) UnmarshalText(text []byte) error

func (Date) Value

func (n Date) Value() (driver.Value, error)

type DateTime

type DateTime struct {
	DateTime time.Time
	Valid    bool
}

func NewDateTime

func NewDateTime(datetime time.Time) DateTime

func (*DateTime) After

func (d *DateTime) After(that *DateTime) bool

func (*DateTime) Before

func (d *DateTime) Before(that *DateTime) bool

func (*DateTime) Equal

func (d *DateTime) Equal(that *DateTime) bool

func (DateTime) IsZero

func (d DateTime) IsZero() bool

func (DateTime) MarshalJSON

func (n DateTime) MarshalJSON() ([]byte, error)

func (DateTime) MarshalText

func (n DateTime) MarshalText() ([]byte, error)

func (*DateTime) Scan

func (n *DateTime) Scan(value interface{}) error

func (*DateTime) UnmarshalJSON

func (n *DateTime) UnmarshalJSON(data []byte) (err error)

func (*DateTime) UnmarshalText

func (n *DateTime) UnmarshalText(text []byte) error

func (DateTime) Value

func (n DateTime) Value() (driver.Value, error)

type Float

type Float struct {
	sql.NullFloat64
}

Float is a nullable float64. It does not consider zero values to be null. It will decode to null, not zero, if null.

func FloatFrom

func FloatFrom(f float64) Float

FloatFrom creates a new Float that will always be valid.

func FloatFromPtr

func FloatFromPtr(f *float64) Float

FloatFromPtr creates a new Float that be null if f is nil.

func NewFloat

func NewFloat(f float64, valid bool) Float

NewFloat creates a new Float

func (Float) IsZero

func (f Float) IsZero() bool

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

func (Float) MarshalJSON

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

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

func (Float) MarshalText

func (f Float) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Float is null.

func (Float) Ptr

func (f Float) Ptr() *float64

Ptr returns a pointer to this Float's value, or a nil pointer if this Float is null.

func (*Float) SetValid

func (f *Float) SetValid(n float64)

SetValid changes this Float's value and also sets it to be non-null.

func (*Float) UnmarshalJSON

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

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

func (*Float) UnmarshalText

func (f *Float) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Float if the input is a blank or not an integer. It will return an error if the input is not an integer, blank, or "null".

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 IntFrom

func IntFrom(i int64) Int

IntFrom creates a new Int that will always be valid.

func IntFromPtr

func IntFromPtr(i *int64) Int

IntFromPtr creates a new Int that be null if i is nil.

func NewInt

func NewInt(i int64, valid bool) Int

NewInt creates a new Int

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) MarshalJSON

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

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

func (Int) MarshalText

func (i Int) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string if this Int is null.

func (Int) Ptr

func (i Int) Ptr() *int64

Ptr returns a pointer to this Int's value, or a nil pointer if this Int is null.

func (*Int) SetValid

func (i *Int) SetValid(n int64)

SetValid changes this Int's value and also sets it to be non-null.

func (Int) String

func (i Int) String() string

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.

func (*Int) UnmarshalText

func (i *Int) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null Int if the input is a blank 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. It supports SQL and JSON serialization. It will marshal to null if null. Blank string input will be considered null.

func NewString

func NewString(s string, valid bool) String

NewString creates a new String

func StringFrom

func StringFrom(s string) String

StringFrom creates a new String that will never be blank.

func StringFromPtr

func StringFromPtr(s *string) String

StringFromPtr creates a new String that be null if s is nil.

func (String) IsZero

func (s String) IsZero() bool

IsZero returns true for null or empty strings, for future omitempty support. (Go 1.4?) Will return false s if blank but non-null.

func (String) MarshalJSON

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

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

func (String) Ptr

func (s String) Ptr() *string

Ptr returns a pointer to this String's value, or a nil pointer if this String is null.

func (*String) SetValid

func (s *String) SetValid(v string)

SetValid changes this String's value and also sets it to be non-null.

func (*String) UnmarshalJSON

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

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

func (s *String) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.

Jump to

Keyboard shortcuts

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