data

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool represents a bool that can be unmarshaled from various JSON types Null values are converted to false instead of preserving null state Accepts: booleans, strings ("1", "true", "success" → true), numbers (non-zero → true), and null (→ false)

func NewBool

func NewBool(value bool) Bool

NewBool creates a new Bool with the given value

func (Bool) Bool

func (b Bool) Bool() bool

Bool returns the bool value

func (Bool) MarshalJSON

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

MarshalJSON implements json.Marshaler for Bool

func (Bool) String

func (b Bool) String() string

String returns the string representation of the boolean

func (*Bool) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for Bool

type Float

type Float float64

Float represents a float64 that can be unmarshaled from various JSON types Null values are converted to zero instead of preserving null state Accepts: floats, integers, string representations of numbers, and null (→ 0.0)

func NewFloat

func NewFloat(value float64) Float

NewFloat creates a new Float with the given value

func (Float) Float64

func (f Float) Float64() float64

Float64 returns the float64 value

func (Float) MarshalJSON

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

MarshalJSON implements json.Marshaler for Float

func (Float) String

func (f Float) String() string

String returns the string representation of the float

func (*Float) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for Float

type Int

type Int int64

Int represents an int64 that can be unmarshaled from various JSON types Null values are converted to zero instead of preserving null state Accepts: integers, floats (truncated), string representations of numbers, and null (→ 0)

func NewInt

func NewInt(value int64) Int

NewInt creates a new Int with the given value

func (Int) Int64

func (i Int) Int64() int64

Int64 returns the int64 value

func (Int) MarshalJSON

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

MarshalJSON implements json.Marshaler for Int

func (Int) String

func (i Int) String() string

String returns the string representation of the integer

func (*Int) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for Int

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool // true if Bool is not null
}

NullBool represents a bool that may be null in JSON Unlike MultiBool, this preserves null values instead of converting them to false Accepts: booleans, string representations ("true", "success", "1" as true), and null

func NewNullBool

func NewNullBool(value bool) NullBool

NewNullBool creates a new valid NullBool with the given value

func (NullBool) MarshalJSON

func (nb NullBool) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullBool

func (NullBool) String

func (nb NullBool) String() string

String returns the string representation of the boolean, or "null" if not valid

func (*NullBool) UnmarshalJSON

func (nb *NullBool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullBool

func (NullBool) ValueOr

func (nb NullBool) ValueOr(fallback bool) bool

ValueOr returns the boolean value if valid, otherwise returns the fallback value

type NullFloat

type NullFloat struct {
	Float float64
	Valid bool // true if Float is not null
}

NullFloat represents a float64 that may be null in JSON Accepts: floats, integers, string representations of numbers, and null

func NewNullFloat

func NewNullFloat(value float64) NullFloat

NewNullFloat creates a new valid NullFloat with the given value

func (NullFloat) MarshalJSON

func (nf NullFloat) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullFloat

func (NullFloat) String

func (nf NullFloat) String() string

String returns the string representation of the float, or "null" if not valid

func (*NullFloat) UnmarshalJSON

func (nf *NullFloat) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullFloat

func (NullFloat) ValueOr

func (nf NullFloat) ValueOr(fallback float64) float64

ValueOr returns the float value if valid, otherwise returns the fallback value

type NullInt

type NullInt struct {
	Int   int64
	Valid bool // true if Int is not null
}

NullInt represents an int64 that may be null in JSON Unlike MultiInt, this preserves null values instead of converting them to zero Accepts: integers, floats (truncated), string representations of numbers, and null

func NewNullInt

func NewNullInt(value int64) NullInt

NewNullInt creates a new valid NullInt with the given value

func (NullInt) MarshalJSON

func (ni NullInt) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullInt

func (NullInt) String

func (ni NullInt) String() string

String returns the string representation of the integer, or "null" if not valid

func (*NullInt) UnmarshalJSON

func (ni *NullInt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullInt

func (NullInt) ValueOr

func (ni NullInt) ValueOr(fallback int64) int64

ValueOr returns the integer value if valid, otherwise returns the fallback value

type NullString

type NullString struct {
	Str   string
	Valid bool // true if Str is not null
}

NullString represents a string that may be null in JSON Unlike MultiString, this preserves null values instead of converting them to empty strings Accepts: strings, numbers (converted to strings), and null

func NewNullString

func NewNullString(value string) NullString

NewNullString creates a new valid NullString with the given value

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullString

func (NullString) String

func (ns NullString) String() string

String returns the string representation, or "null" if not valid

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullString

func (NullString) ValueOr

func (ns NullString) ValueOr(fallback string) string

ValueOr returns the string value if valid, otherwise returns the fallback value

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // true if Time is not null
}

NullTime represents a time.Time that may be null in JSON Unlike MultiDateTime, this preserves null values instead of converting them to zero time Accepts: RFC3339 strings, various datetime formats, and null

func NewNullTime

func NewNullTime(value time.Time) NullTime

NewNullTime creates a new valid NullTime with the given value

func NewNullTimeFromString

func NewNullTimeFromString(value string) (NullTime, error)

NewNullTimeFromString creates a new NullTime by parsing the given string

func (NullTime) IsZero

func (nt NullTime) IsZero() bool

IsZero returns true if the time is not valid or is the zero time

func (NullTime) MarshalJSON

func (nt NullTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullTime

func (NullTime) String

func (nt NullTime) String() string

String returns the string representation of the time, or "null" if not valid

func (NullTime) Unix

func (nt NullTime) Unix() int64

Unix returns the Unix timestamp if valid, otherwise returns 0

func (*NullTime) UnmarshalJSON

func (nt *NullTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullTime

func (NullTime) ValueOr

func (nt NullTime) ValueOr(fallback time.Time) time.Time

ValueOr returns the time value if valid, otherwise returns the fallback value

type NullUint

type NullUint struct {
	Uint  uint64
	Valid bool // true if Uint is not null
}

NullUint represents a uint64 that may be null in JSON Unlike Uint, this preserves null values instead of converting them to zero Accepts: unsigned integers, floats (truncated), string representations of numbers, and null

func NewNullUint

func NewNullUint(value uint64) NullUint

NewNullUint creates a new valid NullUint with the given value

func (NullUint) MarshalJSON

func (nu NullUint) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for NullUint

func (NullUint) String

func (nu NullUint) String() string

String returns the string representation of the uint, or "null" if not valid

func (*NullUint) UnmarshalJSON

func (nu *NullUint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for NullUint

func (NullUint) ValueOr

func (nu NullUint) ValueOr(fallback uint64) uint64

ValueOr returns the uint value if valid, otherwise returns the fallback value

type String

type String string

String represents a string that can be unmarshaled from various JSON types Null values are converted to empty string instead of preserving null state Accepts: strings, numbers (converted to strings), and null (→ "")

func NewString

func NewString(value string) String

NewString creates a new String with the given value

func (String) MarshalJSON

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

MarshalJSON implements json.Marshaler for String

func (String) String

func (s String) String() string

String returns the string value (implements fmt.Stringer)

func (*String) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for String

type Time

type Time time.Time

Time represents a time.Time that can be unmarshaled from various JSON types Null values are converted to zero time instead of preserving null state Accepts: RFC3339 strings, RFC3339Nano strings, and null (→ zero time)

func NewTime

func NewTime(value time.Time) Time

NewTime creates a new Time with the given value

func NewTimeFromString

func NewTimeFromString(s string) (Time, error)

NewTimeFromString creates a new Time by parsing a string

func (Time) IsZero

func (t Time) IsZero() bool

IsZero reports whether t represents the zero time instant

func (Time) MarshalJSON

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

MarshalJSON implements json.Marshaler for Time

func (Time) String

func (t Time) String() string

String returns the string representation of the time

func (Time) Time

func (t Time) Time() time.Time

Time returns the time.Time value

func (*Time) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler for Time

type Uint

type Uint uint64

Uint represents a uint64 that converts null JSON values to zero This is the non-null variant that treats null as 0 For preserving null values, use NullUint instead

func NewUint

func NewUint(value uint64) Uint

NewUint creates a new Uint with the given value

func (Uint) MarshalJSON

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

MarshalJSON implements json.Marshaler for Uint

func (Uint) String

func (u Uint) String() string

String returns the string representation of the uint

func (Uint) Uint64

func (u Uint) Uint64() uint64

Uint64 returns the uint64 value

func (*Uint) UnmarshalJSON

func (u *Uint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler for Uint

Jump to

Keyboard shortcuts

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