null

package
v0.0.0-...-15635d3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package null defines a number of nullable types that bridge the packages database/sql, encoding, encoding/json, and encoding/maps. Many are simple wrappers around atabase/sql types (sql.NullString, sql.NullInt64, etc.), but all implement all of the following interfaces,

  • IsNiler from pyrrho/encoding -- IsNil() bool
  • IsZeroer from pyrrho/encoding -- IsZero() bool
  • Valuer from database/sql/driver -- Value() (driver.Value, error)
  • Scanner from database/sql -- Scan(src interface{}) error
  • Marshaler from encoding/json -- MarshalJSON() ([]byte, error)
  • Unmarshaler from encoding/json -- UnmarshalJSON(data []byte) error
  • Marshaler from pyrrho/encoding/maps -- MarshalMap() (map[string]interface{}, error)
  • Unmarshaler from pyrrho/encoding/maps -- [Pending maps.Unmarshal features]

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 wrapper around the database/sql NullBool type that implements all of the pyrrho/encoding/types interfaces detailed in the package comments that sql.NullBool doesn't implement out of the box.

If the Bool is valid and contains false, it will be considered non-nil, and of zero value.

func NewBool

func NewBool(b bool) Bool

NewBool constructs and returns a new, valid Bool initialized with the value of the given b.

func NullBool

func NullBool() Bool

NullBool constructs and returns a new null Bool.

func (Bool) IsNil

func (b Bool) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if b is null.

func (Bool) IsZero

func (b Bool) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if b is null or if its value is false.

func (Bool) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will encode b into its JSON representation if valid, or 'null' otherwise.

func (Bool) MarshalMapValue

func (b Bool) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode b into its interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*Bool) Null

func (b *Bool) Null()

Null marks b as null with no meaningful value.

func (*Bool) Set

func (b *Bool) Set(v bool)

Set modifies the value stored in b, and guarantees it is valid.

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into b, so long as the provided []byte is a valid jSON representation of a bool or a null.

The keyword 'null' will result in a null NullBool. The keywords 'true' and 'false' will result in a valid NullBool containing the value you would expect. The strings '"true"', '"false"', '"null"', and `""` are considered to be strings -- not keywords -- and will result in an error.

If the decode fails, the value of b will be unchanged.

func (Bool) ValueOrZero

func (b Bool) ValueOrZero() bool

ValueOrZero returns the value of b if it is valid; otherwise, it returns the zero value for a bool (false).

type ByteSlice

type ByteSlice struct {
	ByteSlice []byte
	Valid     bool
}

ByteSlice is a nullable wrapper around the []byte type. It implements all of the pyrrho/encoding/types interfaces detailed in the package comments. This type makes a distinction between nil and valid-but-empty []bytes. It is valid to initialzed a ByteSlice with an empty []byte{}, but it is not valid to initialize a ByteSlice with a []byte(nil). This distinction holds true for the Set, Scan, an Unmarshal function groups.

To maintain consistency with the encoding/json package -- and to ensure we never attempt to marshal non-ASCII characters -- this type will emit base64 encoded strings from MarshalJSON, Value, and MarshalMapValue (when non-null), and expect to receive base64 encoded strings in UnmarshalJSON and Scan.

func NewByteSlice

func NewByteSlice(b []byte) ByteSlice

NewByteSlice constructs and returns a new ByteSlice based on the given []byte b. If b is of zero length the new ByteSlice will be null. Otherwise a new, valid ByteSlice will be initialized with a copy of b.

func NewByteSliceFromBase64

func NewByteSliceFromBase64(b []byte) (ByteSlice, error)

NewByteSliceFromBase64 constructs and returns a new ByteSlice object based on the given base64 encoded []byte b.

func NewByteSliceFromBase64Str

func NewByteSliceFromBase64Str(s string) (ByteSlice, error)

NewByteSliceFromBase64Str constructs and returns a new ByteSlice object based on the given base64 encoded []byte b.

func NewByteSliceStr

func NewByteSliceStr(s string) ByteSlice

NewByteSliceStr constructs and returns a new ByteSlice object based on the given string s. If s is the empty string, the new ByteSlice will be null. Otherwise s will be cast to []byte and used to initialize the new, valid ByteSlice.

func NullByteSlice

func NullByteSlice() ByteSlice

NullByteSlice constructs and returns a new null ByteSlice.

func (ByteSlice) IsNil

func (b ByteSlice) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if b is null.

func (ByteSlice) IsZero

func (b ByteSlice) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if b is null or if its value is false.

func (ByteSlice) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will encode b into its base64 representation if valid, or 'null' otherwise.

func (ByteSlice) MarshalMapValue

func (b ByteSlice) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode b into its base64 encoded interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*ByteSlice) Null

func (b *ByteSlice) Null()

Null marks b as null with no meaningful value.

func (*ByteSlice) Scan

func (b *ByteSlice) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It will receive a value from an SQL database and assign it to b, so long as the provided data can be is a []byte, a string, or nil. Valid data is expected to be base64 encoded.

func (*ByteSlice) Set

func (b *ByteSlice) Set(v []byte)

Set copies the given []byte v into b. If v is of length zero, b will be nulled.

func (*ByteSlice) SetStr

func (b *ByteSlice) SetStr(v string)

SetStr copies the given string v into b. If v is of length zero, b will be nulled.

func (*ByteSlice) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into b, so long as the provided []byte is a valid base64 encoded string or a null.

An empty string will result in a valid-but-empty ByteSlice. The keyword 'null' will result in a null ByteSlice. The string '"null"' is considered to be a string -- not a keyword -- and will result in base64 decoded garbage.

If the decode fails, the value of b will be unchanged.

func (ByteSlice) Value

func (b ByteSlice) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will base64 encode valid values prior to returning them.

func (ByteSlice) ValueOrZero

func (b ByteSlice) ValueOrZero() []byte

ValueOrZero returns the value of b if it is valid; otherwise,it returns an empty []byte.

type Float64

type Float64 struct {
	sql.NullFloat64
}

Float64 is a wrapper around the database/sql NullFloat64 type that implements all of the pyrrho/encoding/types interfaces detailed in the package comments that sql.NullFloat64 doesn't implement out of the box.

If the Float64 is valid and contains 0, it will be considered non-nil, and of zero value.

func NewFloat64

func NewFloat64(f float64) Float64

NewFloat64 constructs and returns a new, valid Float64 initialized with the value of the given f.

func NullFloat64

func NullFloat64() Float64

NullFloat64 constructs and returns a new null Float64.

func (Float64) IsNil

func (f Float64) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if f is null.

func (Float64) IsZero

func (f Float64) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if f is null or if its value is 0.

func (Float64) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will attempt to encode f into its JSON representation if valid. If the contained value is +/-INF or NaN, a json.UnsupportedValueError will be returned. If f is not valid, it will encode to 'null'.

func (Float64) MarshalMapValue

func (f Float64) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode f into its interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*Float64) Null

func (f *Float64) Null()

Null marks f as null with no meaningful value.

func (*Float64) Set

func (f *Float64) Set(v float64)

Set modifies the value stored in f, and guarantees it is valid.

func (*Float64) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into f, so long as the provided []byte is a valid JSON representation of a float or null. The 'null' keyword will decode into a null Float64.

If the decode fails, the value of f will be unchanged.

func (Float64) ValueOrZero

func (f Float64) ValueOrZero() float64

ValueOrZero returns the value of f if it is valid; otherwise it returns the zero value for a float64 (0.0).

type Int64

type Int64 struct {
	sql.NullInt64
}

Int64 is a wrapper around the database/sql NullInt64 type that implements all of the pyrrho/encoding/types interfaces detailed in the package comments that sql.NullInt64 doesn't implement out of the box.

If the Int64 is valid and contains 0, it will be considered non-nil, and of zero value.

func NewInt64

func NewInt64(i int64) Int64

NewInt64 constructs and returns a new, valid Int64 initialized with the value of the given i.

func NullInt64

func NullInt64() Int64

NullInt64 constructs and returns a new null Int64.

func (Int64) IsNil

func (i Int64) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if i is null.

func (Int64) IsZero

func (i Int64) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if i is null or if its value is 0.

func (Int64) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will encode i into its JSON representation if valid, or 'null' otherwise.

func (Int64) MarshalMapValue

func (i Int64) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode i into its interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*Int64) Null

func (i *Int64) Null()

Null marks i as null with no meaningful value.

func (*Int64) Set

func (i *Int64) Set(v int64)

Set modifies the value stored in i, and guarantees it is valid.

func (*Int64) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into i, so long as the provided []byte is a valid JSON representation of an int. The 'null' keyword will decode into a null Int64.

If the decode fails, the value of i will be unchanged.

func (Int64) ValueOrZero

func (i Int64) ValueOrZero() int64

ValueOrZero returns the value of i if it is valid; otherwise it returns the zero value for a int64 (0).

type RawJSON

type RawJSON struct {
	JSON  types.RawJSON
	Valid bool
}

RawJSON is a wrapper around types.RawJSON that makes the type null-aware, in terms of both the JSON 'null' keyword, and SQL NULL values. It implements all of the pyrrho/encoding/types interfaces detailed in the package comments.

func NewJSON

func NewJSON(j types.RawJSON) RawJSON

NewJSON constructs and returns a new RawJSON object based on the given types.RawJSON j. If j is of zero-length the new RawJSON will be null. Otherwise a new, valid RawJSON will be initialized with a copy of j.

func NewJSONStr

func NewJSONStr(s string) RawJSON

NewJSONStr constructs and returns a new RawJSON object based on the given string s. If s is the empty string, the new RawJSON will be null. Otherwise s will be cast to types.RawJSON and used to initialize the new valid RawJSON.

func NullJSON

func NullJSON() RawJSON

NullJSON constructs and returns a new null RawJSON object.

func (RawJSON) IsNil

func (j RawJSON) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if j is null.

func (RawJSON) IsZero

func (j RawJSON) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if j is null or if the contained JSON is a zero value.

func (RawJSON) MarshalJSON

func (j RawJSON) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. It will return the value of j as a JSON-encoded []byte. If j is valid, this function will first validate the contained JSON returning either any encouted parsing errors, or a []byte. If j is null, "null" will be returned, and no validation will occur.

func (RawJSON) MarshalMapValue

func (j RawJSON) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode j into its interface{} representation for use in a map[string]interface{} by passing it through JSON.Unmarshal if valid, or the 'null' keyword otherwise.

func (*RawJSON) Null

func (j *RawJSON) Null()

Null will set j to null; j.Valid will be false, and j.JSON will contain no meaningful value.

func (*RawJSON) Scan

func (j *RawJSON) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It expects to receive a valid JSON value as a string or a []byte, or NULL as a nil from an SQL database. A zero-length string or []byte, or a nil will be considered NULL, and j will be nulled, otherwise the the value will be assigned to j. Scan will not validate the incoming JSON.

func (*RawJSON) Set

func (j *RawJSON) Set(v types.RawJSON)

Set copies the given types.RawJSON value into j. If the given value is of length 0, j will be nulled.

func (*RawJSON) SetStr

func (j *RawJSON) SetStr(v string)

SetStr will copy the contents of v into j. If the given value is an empty string, j will be nulled.

func (*RawJSON) UnmarshalJSON

func (j *RawJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid JSON value, and will assign that value to this RawJSON. If the incoming JSON is the 'null' keyword, j will be nulled. UnmarshalJSON will validate the incoming JSON as part of the "Is this JSON null?" check.

func (RawJSON) Value

func (j RawJSON) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will return the value of j as a driver.Value. If j is valid, this function will first validate the contained JSON returning either any encouted parsing errors, or a []byte as a driver.Value. If j is null, nil will be returned, and no validation will occur.

func (RawJSON) ValueOrZero

func (j RawJSON) ValueOrZero() types.RawJSON

ValueOrZero will return the value of j if it is valid, or a newly constructed zero-value types.RawJSON otherwise.

type SFPoint

type SFPoint struct {
	Point types.SFPoint
	Valid bool
}

SFPoint is a wrapper around types.SFPoint that makes the type null-aware, in terms of both the JSON 'null' keyword, and SQL NULL values. It implements all of the pyrrho/encoding/types interfaces detailed in the package comments.

func NewSFPoint

func NewSFPoint(p types.SFPoint) SFPoint

NewSFPoint constructs and returns a new SFPoint object based on the given types.SFPoint p. If p is nil, the new SFPoint will be null. Otherwise a new, valid SFPoint will be initialized with a copy of p.

func NewSFPointXY

func NewSFPointXY(x float64, y float64) SFPoint

NewSFPointXY constructs and returns a new SFPoint object based on the given longitude and latitude coordinates.

func NewSFPointXYZ

func NewSFPointXYZ(x float64, y float64, z float64) SFPoint

NewSFPointXY constructs and returns a new SFPoint object based on the given longitude, latitude, and altitude coordinates.

func NullSFPoint

func NullSFPoint() SFPoint

NullSFPoint constructs and returns a new null SFPoint object.

func (SFPoint) IsNil

func (p SFPoint) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if p is null.

func (SFPoint) IsZero

func (p SFPoint) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if p is null or if the contained SFPoint is a zero value.

func (SFPoint) MarshalJSON

func (p SFPoint) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p, or "null" if p is null.

func (SFPoint) MarshalMapValue

func (p SFPoint) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode p into its interface{} representation for use in a map[string]interface{} by passing it through JSON.Unmarshal if valid, or the 'null' keyword otherwise.

func (*SFPoint) Null

func (p *SFPoint) Null()

Null will set p to null; p.Valid will be false, and p.Point will contain no meaningful value.

func (*SFPoint) Scan

func (p *SFPoint) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It expects to receive a valid WKB encoded []byte describing a Point, or NULL as a nil from an SQL database. A zero-length or nil []byte will be considered NULL, and p will be nulled. Otherwise, the value will be passed to types.SFPoint to be scanned and parsed as a WKB Point.

func (*SFPoint) Set

func (p *SFPoint) Set(v types.SFPoint)

Set copies the given types.SFPoint value into p. If the given value is nil, p will be nulled.

func (*SFPoint) UnmarshalJSON

func (p *SFPoint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid GeoJSON Geometry of the type Point, and will assign the value of that data to p. If the incoming JSON is the 'null' keyword, p will have no valid value.

func (SFPoint) Value

func (p SFPoint) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will return the value of p as a driver.Value. If p is null, nil will be returned.

func (SFPoint) ValueOrZero

func (p SFPoint) ValueOrZero() types.SFPoint

ValueOrZero will return the value of p if it is valid, or a newly constructed zero-value types.SFPoint otherwise.

type SFPolygon

type SFPolygon struct {
	Polygon types.SFPolygon
	Valid   bool
}

SFPolygon is a wrapper around types.SFPolygon that makes the type null-aware, in terms of both the JSON 'null' keyword, and SQL NULL values. It implements all of the pyrrho/encoding/types interfaces detailed in the package comments.

func NewSFPolygon

func NewSFPolygon(p types.SFPolygon) SFPolygon

NewSFPolygon constructs and returns a new SFPolygon object based on the given types.SFPolygon p. If p is nil, the new SFPolygon will be null. Otherwise a new, valid SFPolygon will be initialized with a copy of p.

func NewSFPolygonXY

func NewSFPolygonXY(external [][2]float64, internals ...[][2]float64) SFPolygon

NewSFPolygonXY constructs and returns a new SFPolygon object based on the given external and (optionally) internal shapes.

func NewSFPolygonXYZ

func NewSFPolygonXYZ(external [][3]float64, internals ...[][3]float64) SFPolygon

NewSFPolygonXY constructs and returns a new SFPolygon object based on the given external and (optionally) internal shapes.

func NullSFPolygon

func NullSFPolygon() SFPolygon

NullSFPolygon constructs and returns a new null SFPolygon object.

func (SFPolygon) IsNil

func (p SFPolygon) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if p is null.

func (SFPolygon) IsZero

func (p SFPolygon) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if p is null or if the contained SFPolygon is a zero value.

func (SFPolygon) MarshalJSON

func (p SFPolygon) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p, or "null" if p is null.

func (SFPolygon) MarshalMapValue

func (p SFPolygon) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode p into its interface{} representation for use in a map[string]interface{} by passing it through JSON.Unmarshal if valid, or the 'null' keyword otherwise.

func (*SFPolygon) Null

func (p *SFPolygon) Null()

Null will set p to null; p.Valid will be false, and p.Polygon will contain no meaningful value.

func (*SFPolygon) Scan

func (p *SFPolygon) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It expects to receive a valid WKB encoded []byte describing a Polygon, or NULL as a nil from an SQL database. A zero-length or nil []byte will be considered NULL, and p will be nulled. Otherwise, the value will be passed to types.SFPolygon to be scanned and parsed as a WKB Polygon.

func (*SFPolygon) Set

func (p *SFPolygon) Set(v types.SFPolygon)

Set copies the given types.SFPolygon value into p. If the given value is nil, p will be nulled.

func (*SFPolygon) UnmarshalJSON

func (p *SFPolygon) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid GeoJSON Geometry of the type Polygon, and will assign the value of that data to p. If the incoming JSON is the 'null' keyword, p will have no valid value.

func (SFPolygon) Value

func (p SFPolygon) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will return the value of p as a driver.Value. If p is null, nil will be returned.

func (SFPolygon) ValueOrZero

func (p SFPolygon) ValueOrZero() types.SFPolygon

ValueOrZero will return the value of p if it is valid, or a newly constructed zero-value types.SFPolygon otherwise.

type String

type String struct {
	sql.NullString
}

String is a wrapper around the database/sql NullString type that implements all of the pyrrho/encoding/types interfaces detailed in the package comments that sql.NullString doesn't implement out of the box.

If the String is valid and contains the empty string, it will be considered non-nil, and of zero value.

func NewString

func NewString(s string) String

NewString constructs and returns a new, valid String initialized with the value of the given s.

func NullString

func NullString() String

NullString constructs and returns a new null String.

func (String) IsNil

func (s String) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if s is null.

func (String) IsZero

func (s String) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if s is null or if its value is the empty string.

func (String) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will return the value of s if valid, otherwise 'null'.

func (String) MarshalMapValue

func (s String) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode s into an interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*String) Null

func (s *String) Null()

Null marks s as null with no meaningful value.

func (*String) Set

func (s *String) Set(v string)

Set modifies the value stored in s, and guarantees it is valid.

func (*String) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into s, so long as the provided []byte is a valid JSON string or a null.

An empty string will result in a valid-but-empty String. The keyword 'null' will result in a null String. The string '"null"' is considered to be a string -- not a keyword -- and will result in a valid String.

If the decode fails, the value of s will be unchanged.

func (String) ValueOrZero

func (s String) ValueOrZero() string

ValueOrZero returns the value of s if it is valid; otherwise it returns the zero value for a string ("").

type Time

type Time struct {
	Time  time.Time
	Valid bool
}

Time is a nullable wrapper around the time.Time type implementing all of the pyrrho/encoding/types interfaces detailed in the package comments.

If the Time is valid and contains the zero time instant, it will be considered non-null, and of zero value.

func NewTime

func NewTime(t time.Time) Time

NewTime constructs and returns a new, valid Time initialized with the value of the given t.

func NewTimeStr

func NewTimeStr(s string) (Time, error)

NewTimeStr parses a given string, s, as an ISO 8601 and returns

func NullTime

func NullTime() Time

NullTime constructs and returns a new null Time.

func (Time) IsNil

func (t Time) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if t is null.

func (Time) IsZero

func (t Time) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if t is null or if its value is the zero time instant.

func (Time) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will encode t into its JSON RFC 3339 string representation if valid, or 'null' otherwise.

func (Time) MarshalMapValue

func (t Time) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode t into an interface{} representation for use in a map[Time]interface{} if valid, or return nil otherwise.

func (*Time) Null

func (t *Time) Null()

Null marks t as null with no meaningful value.

func (*Time) Scan

func (t *Time) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It will receive a value from an SQL database and assign it to t, so long as the provided data is of type nil or time.Time. All other types will result in an error.

func (*Time) Set

func (t *Time) Set(v time.Time)

Set modifies the value stored in t, and guarantees it is valid.

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into t so long as the provided []byte is a valid JSON representation of an ISO 8601 string. Empty strings and the 'null' keyword will both decode into a null NullTime.

If the decode fails, the value of t will be unchanged.

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. As time.Time and nil are both valid types to be stored in a driver.Value, it will return this NullTime's value if valid, or nil otherwise.

func (Time) ValueOrZero

func (t Time) ValueOrZero() time.Time

ValueOrZero returns the value of t if it is valid; otherwise it returns the zero value for a time.Time.

type Uint8

type Uint8 struct {
	Uint8 uint8
	Valid bool
}

Uint8 is a nullable wrapper around the uint8 type that implementing all of the pyrrho/encoding/types interfaces detailed in the package comments.

If the Uint8 is valid and contains 0, it will be considered non-nil, and of zero value.

func NewUint8

func NewUint8(i uint8) Uint8

NewUint8 constructs and returns a new, valid Uint8 initialized with the value of the given i.

func NullUint8

func NullUint8() Uint8

NullUint8 constructs and returns a new null Uint8.

func (Uint8) IsNil

func (i Uint8) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if i is null.

func (Uint8) IsZero

func (i Uint8) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if i is null or if its value is 0.

func (Uint8) MarshalJSON

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

MarshalJSON implements the encoding/json Marshaler interface. It will encode i into its JSON representation if valid, or 'null' otherwise.

func (Uint8) MarshalMapValue

func (i Uint8) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode i into its interface{} representation for use in a map[string]interface{} if valid, or return nil otherwise.

func (*Uint8) Null

func (i *Uint8) Null()

Null marks i as null with no meaningful value.

func (*Uint8) Scan

func (i *Uint8) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It will receive a value from an SQL database and assign it to i, so long as the provided data is of type nil, uint8, string, or another integer or float type that doesn't overflow uint8. All other types will result in an error.

func (*Uint8) Set

func (i *Uint8) Set(v uint8)

Set modifies the value stored in i, and guarantees it is valid.

func (*Uint8) UnmarshalJSON

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

UnmarshalJSON implements the encoding/json Unmarshaler interface. It will decode a given []byte into i, so long as the provided []byte is a valid JSON representation of an int. The 'null' keyword will decode into a null Uint8.

If the decode fails, the value of i will be unchanged.

func (Uint8) Value

func (i Uint8) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. Nil is a valid type to be stored in a driver.Value, but uint8 isn't, so if this Uint8 is valid it will cast its uint8 to an int64.

func (Uint8) ValueOrZero

func (i Uint8) ValueOrZero() uint8

ValueOrZero returns the value of i if it is valid; otherwise it returns the zero value for a uint8 (0).

Jump to

Keyboard shortcuts

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