null

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: Apache-2.0 Imports: 2 Imported by: 3

README

null 🚫

GoDoc Build Status Codecov Go Report Card Version

Simple library for null values in Go

This library provides simple, (mostly) idiomatic primitives for nullable values in Go. It supports Int, Bool, and Float types.

// "b" is null, and ready to use
var b null.Bool

// Or, create a nullable value that's not null
b := null.NewBool(true)

// Set value to false
b.Set(false)

// Set value to true
b.Set(true)

// Get the value
b.Bool()

// Make the value null again
b.Unset()

Pull Requests Welcome

Please use GitHub to make suggestions, pull requests, and enhancements. We're all in this together! 🚫

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

Bool provides a nullable bool

func NewBool

func NewBool(value bool) Bool

NewBool returns a fully populated, nullable bool

func (Bool) Bool

func (b Bool) Bool() bool

Bool returns the actual value of this object

func (Bool) Interface

func (b Bool) Interface() interface{}

Interface returns the boolean value (if present) or NIL

func (Bool) IsNull

func (b Bool) IsNull() bool

IsNull returns TRUE if this value is null

func (Bool) IsPresent

func (b Bool) IsPresent() bool

IsPresent returns TRUE if this value is present

func (Bool) MarshalJSON

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

MarshalJSON implements the json.Marshaller interface

func (*Bool) Set

func (b *Bool) Set(value bool)

Set applies a new value to the nullable item

func (Bool) String

func (b Bool) String() string

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaller interface

func (*Bool) Unset

func (b *Bool) Unset()

Unset removes the value from this item, and sets it to null

type Float

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

Float provides a nullable float64

func NewFloat

func NewFloat(value float64) Float

NewFloat returns a fully populated, nullable float64

func (Float) Float

func (f Float) Float() float64

Float returns the actual value of this object

func (Float) Interface

func (f Float) Interface() interface{}

Interface returns the float64 value (if present) or NIL

func (Float) IsNull

func (f Float) IsNull() bool

IsNull returns TRUE if this value is null

func (Float) IsPresent

func (f Float) IsPresent() bool

IsPresent returns TRUE if this value is present

func (Float) MarshalJSON

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

MarshalJSON implements the json.Marshaller interface

func (*Float) Set

func (f *Float) Set(value float64)

Set applies a new value to the nullable item

func (Float) String

func (f Float) String() string

String returns a string representation of this value

func (*Float) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaller interface

func (*Float) Unset

func (f *Float) Unset()

Unset removes the value from this item, and sets it to null

type Int

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

Int provides a nullable bool

func NewInt

func NewInt(value int) Int

NewInt returns a fully populated, nullable bool

func (Int) Int

func (i Int) Int() int

Int returns the actual value of this object

func (Int) Interface

func (i Int) Interface() interface{}

Interface returns the int value (if present) or NIL

func (Int) IsNull

func (i Int) IsNull() bool

IsNull returns TRUE if this value is null

func (Int) IsPresent

func (i Int) IsPresent() bool

IsPresent returns TRUE if this value is present

func (Int) MarshalJSON

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

MarshalJSON implements the json.Marshaller interface

func (*Int) Set

func (i *Int) Set(value int)

Set applies a new value to the nullable item

func (Int) String

func (i Int) String() string

String returns a string representation of this value

func (*Int) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaller interface

func (*Int) Unset

func (i *Int) Unset()

Unset removes the value from this item, and sets it to null

type Int64

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

Int64 provides a nullable bool

func NewInt64

func NewInt64(value int64) Int64

NewInt64 returns a fully populated, nullable bool

func (Int64) Int64

func (i Int64) Int64() int64

Int64 returns the actual value of this object

func (Int64) Interface

func (i Int64) Interface() interface{}

Interface returns the int value (if present) or NIL

func (Int64) IsNull

func (i Int64) IsNull() bool

IsNull returns TRUE if this value is null

func (Int64) IsPresent

func (i Int64) IsPresent() bool

IsPresent returns TRUE if this value is present

func (Int64) MarshalJSON

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

MarshalJSON implements the json.Marshaller interface

func (*Int64) Set

func (i *Int64) Set(value int64)

Set applies a new value to the nullable item

func (Int64) String

func (i Int64) String() string

String returns a string representation of this value

func (*Int64) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaller interface

func (*Int64) Unset

func (i *Int64) Unset()

Unset removes the value from this item, and sets it to null

type Nullable

type Nullable interface {

	// IsNull returns TRUE if the value of this object is null.  FALSE otherwise.
	IsNull() bool
}

Nullable interface wraps the "IsNull" function, which allows an object to identify if it is a null value or not.

Jump to

Keyboard shortcuts

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