Documentation
¶
Overview ¶
Package value is a dynamic, JSON-compatible value model: a value space with typed, constant-error accessors and the coercion rules a small expression language needs. A decoded JSON document is already a Value, so the package interoperates directly with encoding/json while supplying the typed accessors and arithmetic that raw any values lack.
Index ¶
- func AsBool(v Value) (bool, error)
- func AsFloat(v Value) (float64, error)
- func AsInt(v Value) (int64, error)
- func AsObject(v Value) (map[string]Value, error)
- func AsString(v Value) (string, error)
- func Compare(a, b Value) (int, error)
- func Equal(a, b Value) bool
- func Truthy(v Value) bool
- type Error
- type Kind
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compare ¶
Compare orders a and b, returning -1, 0, or 1. Numbers compare across int/float; strings compare lexically; any other pairing is ErrIncomparable.
Types ¶
type Error ¶
type Error string
Error is the sentinel error type for the value package. Every error the package emits is a constant of this type, matched with errors.Is.
const ( // ErrNotObject is returned when a value is required to be an object. ErrNotObject Error = "value: not an object" // ErrNotList is returned when a value is required to be a list. ErrNotList Error = "value: not a list" // ErrNotString is returned when a value is required to be a string. ErrNotString Error = "value: not a string" // ErrNotNumber is returned when a value is required to be numeric. ErrNotNumber Error = "value: not a number" // ErrNotBool is returned when a value is required to be a bool. ErrNotBool Error = "value: not a bool" // ErrIncomparable is returned when two values cannot be ordered. ErrIncomparable Error = "value: incomparable types" )
type Kind ¶
type Kind int
Kind names the dynamic type of a Value.
const ( // KindNull is the kind of nil. KindNull Kind = iota // KindBool is the kind of a bool. KindBool // KindInt is the kind of an int64. KindInt // KindFloat is the kind of a float64. KindFloat // KindString is the kind of a string. KindString // KindList is the kind of a []Value. KindList // KindObject is the kind of a map[string]Value. KindObject )
type Value ¶
type Value = any
Value is the dynamic value: nil | bool | int64 | float64 | string | []Value | map[string]Value. The alias keeps encoding/json interop direct (a decoded JSON document is already a Value); the accessors below supply the typed, constant-error discipline. Numbers decoded from JSON are float64; numeric literals may be int64. The accessors and arithmetic treat both uniformly.