optional

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

Package optional defines optional versions of primitive types that can be nil. These are useful when performing partial updates of some objects because it is impossible to tell the difference between a value that is explicitly set to its zero value and a value that is not set at all when marshaling a struct with native primitive types.

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 represents an optional boolean value.

func NewBool

func NewBool(b bool) *Bool

NewBool returns a new optional bool set to b.

func NewNilBool

func NewNilBool() *Bool

NewNilBool returns a new optional bool set to nil.

func (*Bool) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

type Int

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

Int represents an optional int.

func NewInt

func NewInt(i int) *Int

NewInt returns a new optional int set to i.

func NewNilInt

func NewNilInt() *Int

NewNilInt returns a new optional int set to nil.

func (*Int) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

type String

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

String represents an optional string.

func NewNilString

func NewNilString() *String

NewNilString returns a new optional string set to nil.

func NewString

func NewString(s string) *String

NewString returns a new optional string set to s.

func (*String) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

type StringSlice

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

StringSlice represents an optional string slice.

func NewNilStringSlice

func NewNilStringSlice() *StringSlice

NewNilStringSlice returns a new optional string slice set to nil.

func NewStringSlice

func NewStringSlice(ss []string) *StringSlice

NewStringSlice returns a new optional string slice set to ss. If ss is nil, it is equivalent to NewNilStringSlice.

func (*StringSlice) MarshalJSON

func (s *StringSlice) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

Jump to

Keyboard shortcuts

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