box

package module
v0.0.0-...-f4572d8 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2014 License: MIT Imports: 2 Imported by: 0

README

box

Use a box around values that can be undefined, unknown, empty, or present.

As Go does not have generics or templates, a box.go.erb is processed to produce box.go with specialized box types for each underlying type. Currently, boxes are defined for bool, float32, float64, int8, int16, int32, int64, string, time.Time, uint8, uint16, uint32, and uint64 types.

If you need additional types, you may want to fork this project into a sub-package and customize the type list in box.go.erb.

Documentation

Overview

Package box stores values that may be undefined, unknown, or empty.

Index

Constants

View Source
const (
	Undefined = iota
	Unknown   = iota
	Empty     = iota
	Full      = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	// contains filtered or unexported fields
}

func NewBool

func NewBool(v bool) (box Bool)

NewBool returns a Bool initialized to v

func (*Bool) Get

func (box *Bool) Get() (bool, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Bool) GetCoerceNil

func (box *Bool) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Bool) GetCoerceZero

func (box *Bool) GetCoerceZero() bool

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Bool) MarshalJSON

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

func (*Bool) MustGet

func (box *Bool) MustGet() bool

MustGet returns the value or panics if box is not full

func (*Bool) Set

func (box *Bool) Set(v bool)

Set places v in box

func (*Bool) SetCoerceNil

func (box *Bool) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Bool) SetCoerceZero

func (box *Bool) SetCoerceZero(v bool, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Bool) SetEmpty

func (box *Bool) SetEmpty()

SetEmpty sets box to Empty

func (*Bool) SetUndefined

func (box *Bool) SetUndefined()

SetUndefined sets box to Undefined

func (*Bool) SetUnknown

func (box *Bool) SetUnknown()

SetUnknown sets box to Unknown

func (*Bool) Status

func (box *Bool) Status() byte

Status returns the box's status

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

func NewFloat32

func NewFloat32(v float32) (box Float32)

NewFloat32 returns a Float32 initialized to v

func (*Float32) Get

func (box *Float32) Get() (float32, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Float32) GetCoerceNil

func (box *Float32) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Float32) GetCoerceZero

func (box *Float32) GetCoerceZero() float32

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Float32) MarshalJSON

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

func (*Float32) MustGet

func (box *Float32) MustGet() float32

MustGet returns the value or panics if box is not full

func (*Float32) Set

func (box *Float32) Set(v float32)

Set places v in box

func (*Float32) SetCoerceNil

func (box *Float32) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Float32) SetCoerceZero

func (box *Float32) SetCoerceZero(v float32, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Float32) SetEmpty

func (box *Float32) SetEmpty()

SetEmpty sets box to Empty

func (*Float32) SetUndefined

func (box *Float32) SetUndefined()

SetUndefined sets box to Undefined

func (*Float32) SetUnknown

func (box *Float32) SetUnknown()

SetUnknown sets box to Unknown

func (*Float32) Status

func (box *Float32) Status() byte

Status returns the box's status

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

func NewFloat64

func NewFloat64(v float64) (box Float64)

NewFloat64 returns a Float64 initialized to v

func (*Float64) Get

func (box *Float64) Get() (float64, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Float64) GetCoerceNil

func (box *Float64) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Float64) GetCoerceZero

func (box *Float64) GetCoerceZero() float64

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Float64) MarshalJSON

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

func (*Float64) MustGet

func (box *Float64) MustGet() float64

MustGet returns the value or panics if box is not full

func (*Float64) Set

func (box *Float64) Set(v float64)

Set places v in box

func (*Float64) SetCoerceNil

func (box *Float64) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Float64) SetCoerceZero

func (box *Float64) SetCoerceZero(v float64, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Float64) SetEmpty

func (box *Float64) SetEmpty()

SetEmpty sets box to Empty

func (*Float64) SetUndefined

func (box *Float64) SetUndefined()

SetUndefined sets box to Undefined

func (*Float64) SetUnknown

func (box *Float64) SetUnknown()

SetUnknown sets box to Unknown

func (*Float64) Status

func (box *Float64) Status() byte

Status returns the box's status

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

func NewInt16

func NewInt16(v int16) (box Int16)

NewInt16 returns a Int16 initialized to v

func (*Int16) Get

func (box *Int16) Get() (int16, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Int16) GetCoerceNil

func (box *Int16) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Int16) GetCoerceZero

func (box *Int16) GetCoerceZero() int16

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Int16) MarshalJSON

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

func (*Int16) MustGet

func (box *Int16) MustGet() int16

MustGet returns the value or panics if box is not full

func (*Int16) Set

func (box *Int16) Set(v int16)

Set places v in box

func (*Int16) SetCoerceNil

func (box *Int16) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Int16) SetCoerceZero

func (box *Int16) SetCoerceZero(v int16, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Int16) SetEmpty

func (box *Int16) SetEmpty()

SetEmpty sets box to Empty

func (*Int16) SetUndefined

func (box *Int16) SetUndefined()

SetUndefined sets box to Undefined

func (*Int16) SetUnknown

func (box *Int16) SetUnknown()

SetUnknown sets box to Unknown

func (*Int16) Status

func (box *Int16) Status() byte

Status returns the box's status

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

func NewInt32

func NewInt32(v int32) (box Int32)

NewInt32 returns a Int32 initialized to v

func (*Int32) Get

func (box *Int32) Get() (int32, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Int32) GetCoerceNil

func (box *Int32) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Int32) GetCoerceZero

func (box *Int32) GetCoerceZero() int32

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Int32) MarshalJSON

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

func (*Int32) MustGet

func (box *Int32) MustGet() int32

MustGet returns the value or panics if box is not full

func (*Int32) Set

func (box *Int32) Set(v int32)

Set places v in box

func (*Int32) SetCoerceNil

func (box *Int32) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Int32) SetCoerceZero

func (box *Int32) SetCoerceZero(v int32, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Int32) SetEmpty

func (box *Int32) SetEmpty()

SetEmpty sets box to Empty

func (*Int32) SetUndefined

func (box *Int32) SetUndefined()

SetUndefined sets box to Undefined

func (*Int32) SetUnknown

func (box *Int32) SetUnknown()

SetUnknown sets box to Unknown

func (*Int32) Status

func (box *Int32) Status() byte

Status returns the box's status

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

func NewInt64

func NewInt64(v int64) (box Int64)

NewInt64 returns a Int64 initialized to v

func (*Int64) Get

func (box *Int64) Get() (int64, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Int64) GetCoerceNil

func (box *Int64) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Int64) GetCoerceZero

func (box *Int64) GetCoerceZero() int64

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Int64) MarshalJSON

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

func (*Int64) MustGet

func (box *Int64) MustGet() int64

MustGet returns the value or panics if box is not full

func (*Int64) Set

func (box *Int64) Set(v int64)

Set places v in box

func (*Int64) SetCoerceNil

func (box *Int64) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Int64) SetCoerceZero

func (box *Int64) SetCoerceZero(v int64, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Int64) SetEmpty

func (box *Int64) SetEmpty()

SetEmpty sets box to Empty

func (*Int64) SetUndefined

func (box *Int64) SetUndefined()

SetUndefined sets box to Undefined

func (*Int64) SetUnknown

func (box *Int64) SetUnknown()

SetUnknown sets box to Unknown

func (*Int64) Status

func (box *Int64) Status() byte

Status returns the box's status

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

func NewInt8

func NewInt8(v int8) (box Int8)

NewInt8 returns a Int8 initialized to v

func (*Int8) Get

func (box *Int8) Get() (int8, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Int8) GetCoerceNil

func (box *Int8) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Int8) GetCoerceZero

func (box *Int8) GetCoerceZero() int8

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (Int8) MarshalJSON

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

func (*Int8) MustGet

func (box *Int8) MustGet() int8

MustGet returns the value or panics if box is not full

func (*Int8) Set

func (box *Int8) Set(v int8)

Set places v in box

func (*Int8) SetCoerceNil

func (box *Int8) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Int8) SetCoerceZero

func (box *Int8) SetCoerceZero(v int8, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Int8) SetEmpty

func (box *Int8) SetEmpty()

SetEmpty sets box to Empty

func (*Int8) SetUndefined

func (box *Int8) SetUndefined()

SetUndefined sets box to Undefined

func (*Int8) SetUnknown

func (box *Int8) SetUnknown()

SetUnknown sets box to Unknown

func (*Int8) Status

func (box *Int8) Status() byte

Status returns the box's status

type String

type String struct {
	// contains filtered or unexported fields
}

func NewString

func NewString(v string) (box String)

NewString returns a String initialized to v

func (*String) Get

func (box *String) Get() (string, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*String) GetCoerceNil

func (box *String) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*String) GetCoerceZero

func (box *String) GetCoerceZero() string

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (String) MarshalJSON

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

func (*String) MustGet

func (box *String) MustGet() string

MustGet returns the value or panics if box is not full

func (*String) Set

func (box *String) Set(v string)

Set places v in box

func (*String) SetCoerceNil

func (box *String) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*String) SetCoerceZero

func (box *String) SetCoerceZero(v string, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*String) SetEmpty

func (box *String) SetEmpty()

SetEmpty sets box to Empty

func (*String) SetUndefined

func (box *String) SetUndefined()

SetUndefined sets box to Undefined

func (*String) SetUnknown

func (box *String) SetUnknown()

SetUnknown sets box to Unknown

func (*String) Status

func (box *String) Status() byte

Status returns the box's status

type Time

type Time struct {
	// contains filtered or unexported fields
}

func NewTime

func NewTime(v time.Time) (box Time)

NewTime returns a Time initialized to v

func (*Time) Get

func (box *Time) Get() (time.Time, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*Time) GetCoerceNil

func (box *Time) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*Time) GetCoerceZero

func (box *Time) GetCoerceZero() time.Time

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (*Time) MustGet

func (box *Time) MustGet() time.Time

MustGet returns the value or panics if box is not full

func (*Time) Set

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

Set places v in box

func (*Time) SetCoerceNil

func (box *Time) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*Time) SetCoerceZero

func (box *Time) SetCoerceZero(v time.Time, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*Time) SetEmpty

func (box *Time) SetEmpty()

SetEmpty sets box to Empty

func (*Time) SetUndefined

func (box *Time) SetUndefined()

SetUndefined sets box to Undefined

func (*Time) SetUnknown

func (box *Time) SetUnknown()

SetUnknown sets box to Unknown

func (*Time) Status

func (box *Time) Status() byte

Status returns the box's status

type UInt16

type UInt16 struct {
	// contains filtered or unexported fields
}

func NewUInt16

func NewUInt16(v uint16) (box UInt16)

NewUInt16 returns a UInt16 initialized to v

func (*UInt16) Get

func (box *UInt16) Get() (uint16, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*UInt16) GetCoerceNil

func (box *UInt16) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*UInt16) GetCoerceZero

func (box *UInt16) GetCoerceZero() uint16

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (UInt16) MarshalJSON

func (box UInt16) MarshalJSON() ([]byte, error)

func (*UInt16) MustGet

func (box *UInt16) MustGet() uint16

MustGet returns the value or panics if box is not full

func (*UInt16) Set

func (box *UInt16) Set(v uint16)

Set places v in box

func (*UInt16) SetCoerceNil

func (box *UInt16) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*UInt16) SetCoerceZero

func (box *UInt16) SetCoerceZero(v uint16, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*UInt16) SetEmpty

func (box *UInt16) SetEmpty()

SetEmpty sets box to Empty

func (*UInt16) SetUndefined

func (box *UInt16) SetUndefined()

SetUndefined sets box to Undefined

func (*UInt16) SetUnknown

func (box *UInt16) SetUnknown()

SetUnknown sets box to Unknown

func (*UInt16) Status

func (box *UInt16) Status() byte

Status returns the box's status

type UInt32

type UInt32 struct {
	// contains filtered or unexported fields
}

func NewUInt32

func NewUInt32(v uint32) (box UInt32)

NewUInt32 returns a UInt32 initialized to v

func (*UInt32) Get

func (box *UInt32) Get() (uint32, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*UInt32) GetCoerceNil

func (box *UInt32) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*UInt32) GetCoerceZero

func (box *UInt32) GetCoerceZero() uint32

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (UInt32) MarshalJSON

func (box UInt32) MarshalJSON() ([]byte, error)

func (*UInt32) MustGet

func (box *UInt32) MustGet() uint32

MustGet returns the value or panics if box is not full

func (*UInt32) Set

func (box *UInt32) Set(v uint32)

Set places v in box

func (*UInt32) SetCoerceNil

func (box *UInt32) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*UInt32) SetCoerceZero

func (box *UInt32) SetCoerceZero(v uint32, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*UInt32) SetEmpty

func (box *UInt32) SetEmpty()

SetEmpty sets box to Empty

func (*UInt32) SetUndefined

func (box *UInt32) SetUndefined()

SetUndefined sets box to Undefined

func (*UInt32) SetUnknown

func (box *UInt32) SetUnknown()

SetUnknown sets box to Unknown

func (*UInt32) Status

func (box *UInt32) Status() byte

Status returns the box's status

type UInt64

type UInt64 struct {
	// contains filtered or unexported fields
}

func NewUInt64

func NewUInt64(v uint64) (box UInt64)

NewUInt64 returns a UInt64 initialized to v

func (*UInt64) Get

func (box *UInt64) Get() (uint64, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*UInt64) GetCoerceNil

func (box *UInt64) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*UInt64) GetCoerceZero

func (box *UInt64) GetCoerceZero() uint64

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (UInt64) MarshalJSON

func (box UInt64) MarshalJSON() ([]byte, error)

func (*UInt64) MustGet

func (box *UInt64) MustGet() uint64

MustGet returns the value or panics if box is not full

func (*UInt64) Set

func (box *UInt64) Set(v uint64)

Set places v in box

func (*UInt64) SetCoerceNil

func (box *UInt64) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*UInt64) SetCoerceZero

func (box *UInt64) SetCoerceZero(v uint64, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*UInt64) SetEmpty

func (box *UInt64) SetEmpty()

SetEmpty sets box to Empty

func (*UInt64) SetUndefined

func (box *UInt64) SetUndefined()

SetUndefined sets box to Undefined

func (*UInt64) SetUnknown

func (box *UInt64) SetUnknown()

SetUnknown sets box to Unknown

func (*UInt64) Status

func (box *UInt64) Status() byte

Status returns the box's status

type UInt8

type UInt8 struct {
	// contains filtered or unexported fields
}

func NewUInt8

func NewUInt8(v uint8) (box UInt8)

NewUInt8 returns a UInt8 initialized to v

func (*UInt8) Get

func (box *UInt8) Get() (uint8, bool)

Get returns the value and present. present is true only if the box is Full and value is valid

func (*UInt8) GetCoerceNil

func (box *UInt8) GetCoerceNil() interface{}

GetCoerceNil returns the value if the box is full, otherwise it returns nil

func (*UInt8) GetCoerceZero

func (box *UInt8) GetCoerceZero() uint8

GetCoerceZero returns value if the box is full, otherwise it returns the zero value

func (UInt8) MarshalJSON

func (box UInt8) MarshalJSON() ([]byte, error)

func (*UInt8) MustGet

func (box *UInt8) MustGet() uint8

MustGet returns the value or panics if box is not full

func (*UInt8) Set

func (box *UInt8) Set(v uint8)

Set places v in box

func (*UInt8) SetCoerceNil

func (box *UInt8) SetCoerceNil(v interface{}, nilStatus byte)

SetCoerceNil places v in box if v is not nil, otherwise it sets box to nilStatus

func (*UInt8) SetCoerceZero

func (box *UInt8) SetCoerceZero(v uint8, zeroStatus byte)

SetCoerceZero places v in box if v is not the zero value, otherwise it sets box to zeroStatus

func (*UInt8) SetEmpty

func (box *UInt8) SetEmpty()

SetEmpty sets box to Empty

func (*UInt8) SetUndefined

func (box *UInt8) SetUndefined()

SetUndefined sets box to Undefined

func (*UInt8) SetUnknown

func (box *UInt8) SetUnknown()

SetUnknown sets box to Unknown

func (*UInt8) Status

func (box *UInt8) Status() byte

Status returns the box's status

Jump to

Keyboard shortcuts

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