option

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: ISC Imports: 3 Imported by: 4

Documentation

Overview

Package option provides the ability to create omittable primitives. This is accomplished by pointerrizing common primitive types so that they may assume a nil value, which is considered as omitted by encoding/json. To generate pointerrized primitives, there are helper functions NewT() for each option type.

Index

Constants

This section is empty.

Variables

View Source
var (
	True  = newBool(true)
	False = newBool(false)
)
View Source
var (
	// NullBool serializes to JSON null.
	NullBool     = &NullableBoolData{}
	NullableTrue = &NullableBoolData{
		Val:  true,
		Init: true,
	}
	NullableFalse = &NullableBoolData{
		Val:  false,
		Init: true,
	}
)
View Source
var NullColor = &NullableColorData{}

NullColor serializes to JSON null.

View Source
var NullInt = &NullableIntData{}

NullInt serializes to JSON null.

View Source
var NullString = &NullableStringData{}

NullString serializes to JSON null.

View Source
var NullUint = &NullableUintData{}

NullUint serializes to JSON null.

View Source
var ZeroInt = NewInt(0)

ZeroInt is an Int with 0 as value.

View Source
var ZeroSeconds = NewSeconds(0)

ZeroSeconds are 0 Seconds.

View Source
var ZeroUint = NewUint(0)

ZeroUint is a Uint with 0 as value.

Functions

This section is empty.

Types

type Bool

type Bool *bool

Bool is the option type for bool.

type Color

type Color = *discord.Color

Color is the option type for discord.Color.

func NewColor

func NewColor(s discord.Color) Color

NewString creates a new Color with the value of the passed discord.Color.

type Int

type Int *int

Int is the option type for integers (int).

func NewInt

func NewInt(i int) Int

NewInt creates a new Int using the value of the passed int.

type NullableBool

type NullableBool = *NullableBoolData

NullableBool is the nullable type for bool.

type NullableBoolData

type NullableBoolData struct {
	Val  bool
	Init bool
}

func (NullableBoolData) MarshalJSON

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

func (*NullableBoolData) UnmarshalJSON

func (b *NullableBoolData) UnmarshalJSON(json []byte) (err error)

type NullableColor

type NullableColor = *NullableColorData

Nullable is a nullable version of discord.Color.

func NewNullableColor

func NewNullableColor(v discord.Color) NullableColor

NewNullableColor creates a new non-null NullableColor using the value of the passed discord.Color.

type NullableColorData

type NullableColorData struct {
	Val  discord.Color
	Init bool
}

func (NullableColorData) MarshalJSON

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

func (*NullableColorData) UnmarshalJSON

func (i *NullableColorData) UnmarshalJSON(json []byte) error

type NullableInt

type NullableInt = *NullableIntData

NullableInt is a nullable version of an integer (int).

func NewNullableInt

func NewNullableInt(v int) NullableInt

NewInt creates a new non-null NullableInt using the value of the passed int.

type NullableIntData

type NullableIntData struct {
	Val  int
	Init bool
}

func (NullableIntData) MarshalJSON

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

func (*NullableIntData) UnmarshalJSON

func (i *NullableIntData) UnmarshalJSON(json []byte) error

type NullableString

type NullableString = *NullableStringData

NullableString is a nullable version of a string.

func NewNullableString

func NewNullableString(v string) NullableString

NewNullableString creates a new non-null NullableString with the value of the passed string.

type NullableStringData

type NullableStringData struct {
	Val  string
	Init bool
}

func (NullableStringData) MarshalJSON

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

func (*NullableStringData) UnmarshalJSON

func (s *NullableStringData) UnmarshalJSON(b []byte) error

type NullableUint

type NullableUint = *NullableUintData

NullableUint is a nullable version of an unsigned integer (uint).

func NewNullableUint

func NewNullableUint(v uint) NullableUint

NewUint creates a new non-null NullableUint using the value of the passed uint.

type NullableUintData

type NullableUintData struct {
	Val  uint
	Init bool
}

func (NullableUintData) MarshalJSON

func (u NullableUintData) MarshalJSON() ([]byte, error)

func (*NullableUintData) UnmarshalJSON

func (u *NullableUintData) UnmarshalJSON(json []byte) error

type Seconds

type Seconds = *discord.Seconds

Seconds is the option type for discord.Seconds.

func NewSeconds

func NewSeconds(s discord.Seconds) Seconds

NewString creates a new Seconds with the value of the passed discord.Seconds.

type String

type String *string

String is the option type for strings.

func NewString

func NewString(s string) String

NewString creates a new String with the value of the passed string.

type Uint

type Uint *uint

Uint is the option type for unsigned integers (uint).

func NewUint

func NewUint(u uint) Uint

NewUint creates a new Uint using the value of the passed uint.

Jump to

Keyboard shortcuts

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