types

package
v0.0.0-...-8d3c8d6 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package types defines common types to work with json.

The JSON grammar defines four primitive types: strings, numbers, booleans and null.

The null type may only have the single value "null".

A value may be either defined or undefined. Notice that "null" doesn't mean undefined.

An undefined value will marshal as empty in JSON, whereas a "null" will unmarshal as the "null" token.

Strings, numbers and booleans may not be null. This package exposes a Nullable wrapper to support types that may be string or null, numbers or null and boolean or null.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero numerical value
	Zero = Number{Value: []byte{'0'}}
	// True JSON value
	True = Boolean{Value: true, /* contains filtered or unexported fields */}
	// False JSON value
	False = Boolean{Value: false, /* contains filtered or unexported fields */}
	// EmptyString is the empty string ""
	EmptyString = String{Value: []byte{}}
	// Null JSON value
	Null = NullType{/* contains filtered or unexported fields */}
)

Functions

func CompareNumbers

func CompareNumbers(a, b Number) int

func Equal

func Equal(a, b Number) bool

func Greater

func Greater(a, b Number) bool

func GreaterOrEqual

func GreaterOrEqual(a, b Number) bool

func Less

func Less(a, b Number) bool

func LessOrEqual

func LessOrEqual(a, b Number) bool

Types

type Boolean

type Boolean struct {
	Value bool
	// contains filtered or unexported fields
}

Boolean represents a JSON boolean value.

func (Boolean) Bool

func (b Boolean) Bool() bool

func (Boolean) IsDefined

func (b Boolean) IsDefined() bool

func (*Boolean) Set

func (b *Boolean) Set(v bool)

func (Boolean) String

func (b Boolean) String() string

func (Boolean) With

func (b Boolean) With(v bool) Boolean

type BytesLoaderFunc

type BytesLoaderFunc func(string) ([]byte, error)

TODO: should be from reader

type Definable

type Definable interface {
	IsDefined() bool
}

type DocumentShareable

type DocumentShareable interface {
	// Loader function to grab JSON from a remote or local file location.
	Loader() BytesLoaderFunc
}

DocumentShareable allows a [stores.Store] object to share services across the [json.Document]s it holds. TODO: don't know yet

type ErrStateSetter

type ErrStateSetter interface {
	SetErr(error)
}

ErrSetter is the common interface for all types that accept that callers may override their internal error state.

type NullType

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

func (NullType) IsDefined

func (n NullType) IsDefined() bool

func (*NullType) Set

func (n *NullType) Set()

func (NullType) String

func (n NullType) String() string

func (*NullType) Unset

func (n *NullType) Unset()

type Nullable

type Nullable[T Definable] struct {
	Inner T
	// contains filtered or unexported fields
}

Nullable is a wrapper type for any type that supports IsDefined() bool.

func (Nullable[T]) IsDefined

func (n Nullable[T]) IsDefined() bool

func (Nullable[T]) IsNull

func (n Nullable[T]) IsNull() bool

func (*Nullable[T]) SetNull

func (n *Nullable[T]) SetNull()

func (Nullable[T]) WithNull

func (n Nullable[T]) WithNull() Nullable[T]

type Number

type Number struct {
	Value []byte
}

Number represents a JSON number.

func ToNumber

func ToNumber[T conv.Numerical](n T) Number

ToNumber convert any native go numerical type to a JSON Number (complex numbers are not supported).

func (Number) IsDefined

func (n Number) IsDefined() bool

func (Number) Preferred

func (n Number) Preferred() any

func (Number) String

func (n Number) String() string

type Resettable

type Resettable = pools.Resettable

Resettable is implemented by types that can reset their state.

This is useful when working with pools.

type String

type String struct {
	Value []byte
}

String represent a JSON string.

func (String) IsDefined

func (s String) IsDefined() bool

func (String) String

func (s String) String() string

type WithErrState

type WithErrState interface {
	Ok() bool
	Err() error
}

WithErrState is the common interface for all types that manage an internal error state.

This is useful to descend a hierarchical structure without stacking return errors.

Jump to

Keyboard shortcuts

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