nillabletypes

package module
v0.0.0-...-1f3ee7b Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

README

nillabletypes - A library of nil- and initialization-aware types in Go

nillabletypes is a library of Go types that provide nil and initialized states.

The nil state is useful when you'd like to communicate that a scalar value does not exist.

The initialized state is useful when you'd like to ensure that a variable's value has been set, typically after you pass an existing variable by reference to some other function.

Available Types

  • Bool: represents a nil-able bool type.
  • Float: represents a nil-able float64 type.
  • Int32: represents a nil-able int32 type.
  • Int64: represents a nil-able int64 type.
  • Int: a typealias for either Int32 or Int64, depending on whether the target architecture is 32- or 64-bit.
  • String: represents a nil-able string type.
  • Time: represents a nil-able `time.Time`` type.
  • Date: represents a nil-able date encoded as an ISO string.
  • Uint32: represents a nil-able uint32 type.
  • UUID: represents a nil-able UUID type.

Supported Interfaces

Each type satisfies the following interfaces:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StringsToUUIDs

func StringsToUUIDs(ids []string) []uuid.UUID

Types

type Bool

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

Bool represents a nil-able bool

func NewBool

func NewBool(v bool) Bool

NewBool makes a new non-nil Bool

func NilBool

func NilBool() Bool

NilBool makes a new nil Bool

func (Bool) Bool

func (v Bool) Bool() bool

Bool returns the built-in bool value

func (Bool) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (Bool) Nil

func (v Bool) Nil() bool

Nil returns whether this scalar is nil

func (*Bool) Scan

func (v *Bool) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Bool) String

func (v Bool) String() string

String implements the fmt.Stringer interface

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface

func (Bool) Value

func (v Bool) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Date

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

Date represents a nil-able date encoded as ISO

func NewDate

func NewDate(v string) Date

NewDate makes a new non-nil Date

func NilDate

func NilDate() Date

NilDate makes a new nil Date

func (Date) DaysAgo

func (v Date) DaysAgo() (Int64, error)

DaysAgo returns the number of days elapsed since Date

func (Date) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (Date) Nil

func (v Date) Nil() bool

Nil returns whether this scalar is nil

func (*Date) Scan

func (v *Date) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Date) String

func (v Date) String() string

String implements the fmt.Stringer interface

func (*Date) UnmarshalJSON

func (v *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

func (Date) Value

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

Value implements the driver.Valuer interface

type Float

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

Float represents a nil-able float

func NewFloat

func NewFloat(v float64) Float

NewFloat makes a new non-nil Float

func NilFloat

func NilFloat() Float

NilFloat makes a new nil Float

func (Float) Float

func (v Float) Float() float64

Float returns the built-in float64 value

func (Float) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (Float) Nil

func (v Float) Nil() bool

Nil returns whether this scalar is nil

func (*Float) Scan

func (v *Float) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Float) String

func (v Float) String() string

String implements the fmt.Stringer interface

func (*Float) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface

func (Float) Value

func (v Float) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Int

type Int = Int64

Int represents a nil-able int

func NewInt

func NewInt(v int) Int

NewInt makes a new non-nil Int

func NilInt

func NilInt() Int

NilInt makes a new nil Int

func (Int) Int

func (v Int) Int() int

Int returns the built-in int value

type Int32

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

Int32 represents a nil-able int

func NewInt32

func NewInt32(v int32) Int32

NewInt32 makes a new non-nil Int

func NilInt32

func NilInt32() Int32

NilInt32 makes a new nil Int

func (Int32) Int32

func (v Int32) Int32() int32

Int32 returns the built-in int32 value

func (Int32) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (Int32) Nil

func (v Int32) Nil() bool

Nil returns whether this scalar is nil

func (*Int32) Scan

func (v *Int32) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Int32) String

func (v Int32) String() string

String implements the fmt.Stringer interface

func (*Int32) UnmarshalJSON

func (v *Int32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

func (Int32) Value

func (v Int32) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Int64

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

Int64 represents a nil-able int

func NewInt64

func NewInt64(v int64) Int64

NewInt64 makes a new non-nil Int

func NilInt64

func NilInt64() Int64

NilInt64 makes a new nil Int

func (Int64) Int64

func (v Int64) Int64() int64

Int64 returns the built-in int64 value

func (Int64) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (Int64) Nil

func (v Int64) Nil() bool

Nil returns whether this scalar is nil

func (*Int64) Scan

func (v *Int64) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Int64) String

func (v Int64) String() string

String implements the fmt.Stringer interface

func (*Int64) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface

func (Int64) Value

func (v Int64) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type String

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

String represents a nil-able string

func NewString

func NewString(v string) String

NewString makes a new non-nil String

func NilString

func NilString() String

NilString makes a new nil String

func (String) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface

func (String) Nil

func (v String) Nil() bool

Nil returns whether this scalar is nil

func (*String) Scan

func (v *String) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (String) String

func (v String) String() string

String implements the fmt.Stringer interface

func (*String) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface

func (String) Value

func (v String) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Time

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

func NewTime

func NewTime(v time.Time) Time

func NilTime

func NilTime() Time

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler

func (Time) Nil

func (v Time) Nil() bool

func (*Time) Scan

func (v *Time) Scan(src any) error

Scan implements sql.Scanner

func (*Time) ScanTimestamp

func (v *Time) ScanTimestamp(src pgtype.Timestamp) error

func (*Time) ScanTimestamptz

func (v *Time) ScanTimestamptz(src pgtype.Timestamptz) error

func (Time) Time

func (v Time) Time() time.Time

func (Time) TimestampValue

func (v Time) TimestampValue() (pgtype.Timestamp, error)

func (Time) TimestamptzValue

func (v Time) TimestamptzValue() (pgtype.Timestamptz, error)

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler

func (Time) Value

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

Value implements the driver.Valuer interface

type UUID

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

UUID represents a nil-able UUID

func NewUUID

func NewUUID(v uuid.UUID) UUID

NewUUID makes a new non-nil UUID

func NilUUID

func NilUUID() UUID

NilUUID makes a new nil UUID

func (UUID) MarshalJSON

func (v UUID) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (UUID) Nil

func (v UUID) Nil() bool

Nil returns whether this scalar is nil

func (*UUID) Scan

func (v *UUID) Scan(src any) error

Scan implements the sql.Scanner interface

func (*UUID) ScanUUID

func (v *UUID) ScanUUID(src pgtype.UUID) error

ScanUUID implements the pgtype.UUIDScanner interface

func (UUID) String

func (v UUID) String() string

String implements the fmt.Stringer interface

func (UUID) UUID

func (v UUID) UUID() uuid.UUID

func (*UUID) UUIDValue

func (v *UUID) UUIDValue() (pgtype.UUID, error)

UUIDValue implements the pgtype.UUIDValuer interface

func (*UUID) UnmarshalJSON

func (v *UUID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

func (UUID) Value

func (v UUID) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type Uint32

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

Uint32 represents a nil-able int

func NewUint32

func NewUint32(v uint32) Uint32

NewUint32 makes a new non-nil Uint32

func NilUint32

func NilUint32() Uint32

NilUint32 makes a new nil Uint32

func (Uint32) MarshalJSON

func (v Uint32) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (Uint32) Nil

func (v Uint32) Nil() bool

Nil returns whether this scalar is nil

func (*Uint32) Scan

func (v *Uint32) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (Uint32) String

func (v Uint32) String() string

String implements the fmt.Stringer interface

func (Uint32) Uint32

func (v Uint32) Uint32() uint32

Uint32 returns the built-in Uint32 value

func (*Uint32) UnmarshalJSON

func (v *Uint32) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

func (Uint32) Value

func (v Uint32) Value() (driver.Value, error)

Value implements the driver.Valuer interface

Jump to

Keyboard shortcuts

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