model

package
v3.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 7 Imported by: 0

README

Model

The model package contains the Value struct and functionality for the application.

model.Value is just a wrapper around reflect.Value but provides some additional logic for easier use.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrCouldNotUnpackToType

type ErrCouldNotUnpackToType struct {
	Type reflect.Type
}

func (ErrCouldNotUnpackToType) Error

func (e ErrCouldNotUnpackToType) Error() string

type ErrIncompatibleTypes

type ErrIncompatibleTypes struct {
	A *Value
	B *Value
}

ErrIncompatibleTypes is returned when two values are incompatible.

func (ErrIncompatibleTypes) Error

func (e ErrIncompatibleTypes) Error() string

Error returns the error message.

type ErrUnexpectedType

type ErrUnexpectedType struct {
	Expected Type
	Actual   Type
}

func (ErrUnexpectedType) Error

func (e ErrUnexpectedType) Error() string

type ErrUnexpectedTypes

type ErrUnexpectedTypes struct {
	Expected []Type
	Actual   Type
}

func (ErrUnexpectedTypes) Error

func (e ErrUnexpectedTypes) Error() string

type KeyValue

type KeyValue struct {
	Key   string
	Value *Value
}

KeyValue represents a key value pair.

type MapKeyNotFound

type MapKeyNotFound struct {
	Key string
}

MapKeyNotFound is returned when a key is not found in a map.

func (MapKeyNotFound) Error

func (e MapKeyNotFound) Error() string

Error returns the error message.

type SliceIndexOutOfRange

type SliceIndexOutOfRange struct {
	Index int
}

SliceIndexOutOfRange is returned when an index is invalid.

func (SliceIndexOutOfRange) Error

func (e SliceIndexOutOfRange) Error() string

Error returns the error message.

type Type

type Type string
const (
	TypeString  Type = "string"
	TypeInt     Type = "int"
	TypeFloat   Type = "float"
	TypeBool    Type = "bool"
	TypeMap     Type = "map"
	TypeSlice   Type = "array"
	TypeUnknown Type = "unknown"
	TypeNull    Type = "null"
)

func (Type) String

func (t Type) String() string

type Value

type Value struct {
	Metadata map[string]any
	// contains filtered or unexported fields
}

Value represents a value.

func NewBoolValue

func NewBoolValue(x bool) *Value

NewBoolValue creates a new Value with a bool value.

func NewFloatValue

func NewFloatValue(x float64) *Value

NewFloatValue creates a new Value with a float value.

func NewIntValue

func NewIntValue(x int64) *Value

NewIntValue creates a new Value with an int value.

func NewMapValue

func NewMapValue() *Value

NewMapValue creates a new map value.

func NewNestedValue

func NewNestedValue(v *Value) *Value

NewNestedValue creates a new nested value.

func NewNullValue

func NewNullValue() *Value

NewNullValue creates a new Value with a nil value.

func NewSliceValue

func NewSliceValue() *Value

NewSliceValue returns a new slice value.

func NewStringValue

func NewStringValue(x string) *Value

NewStringValue creates a new Value with a string value.

func NewValue

func NewValue(v any) *Value

NewValue creates a new value.

func (*Value) Add

func (v *Value) Add(other *Value) (*Value, error)

Add adds two values together.

func (*Value) Append

func (v *Value) Append(val *Value) error

Append appends a value to the slice.

func (*Value) BoolValue

func (v *Value) BoolValue() (bool, error)

BoolValue returns the bool value of the Value.

func (*Value) Compare

func (v *Value) Compare(other *Value) (int, error)

Compare compares two values.

func (*Value) Copy

func (v *Value) Copy() (*Value, error)

func (*Value) DeleteMapKey

func (v *Value) DeleteMapKey(key string) error

DeleteMapKey deletes the key from the map.

func (*Value) Divide

func (v *Value) Divide(other *Value) (*Value, error)

Divide returns the result of dividing the value by another value.

func (*Value) Equal

func (v *Value) Equal(other *Value) (*Value, error)

Equal compares two values.

func (*Value) EqualTypeValue

func (v *Value) EqualTypeValue(other *Value) (bool, error)

EqualTypeValue compares two values of the same type.

func (*Value) FloatValue

func (v *Value) FloatValue() (float64, error)

FloatValue returns the float value of the Value.

func (*Value) GetMapKey

func (v *Value) GetMapKey(key string) (*Value, error)

GetMapKey returns the value at the specified key in the map.

func (*Value) GetSliceIndex

func (v *Value) GetSliceIndex(i int) (*Value, error)

GetSliceIndex returns the value at the specified index in the slice.

func (*Value) GoValue added in v3.1.4

func (v *Value) GoValue() (any, error)

GoValue returns the value as a native Go value.

func (*Value) GreaterThan

func (v *Value) GreaterThan(other *Value) (*Value, error)

GreaterThan compares two values.

func (*Value) GreaterThanOrEqual

func (v *Value) GreaterThanOrEqual(other *Value) (*Value, error)

GreaterThanOrEqual compares two values.

func (*Value) IntValue

func (v *Value) IntValue() (int64, error)

IntValue returns the int value of the Value.

func (*Value) Interface

func (v *Value) Interface() any

Interface returns the value as an interface.

func (*Value) IsBool

func (v *Value) IsBool() bool

IsBool returns true if the value is a bool.

func (*Value) IsBranch

func (v *Value) IsBranch() bool

IsBranch returns true if the value is a branched value.

func (*Value) IsFloat

func (v *Value) IsFloat() bool

IsFloat returns true if the value is a float.

func (*Value) IsIgnore

func (v *Value) IsIgnore() bool

IsIgnore returns true if value should be ignored.

func (*Value) IsInt

func (v *Value) IsInt() bool

IsInt returns true if the value is an int.

func (*Value) IsMap

func (v *Value) IsMap() bool

IsMap returns true if the value is a map.

func (*Value) IsNull

func (v *Value) IsNull() bool

IsNull returns true if the value is null.

func (*Value) IsScalar

func (v *Value) IsScalar() bool

IsScalar returns true if the type is scalar.

func (*Value) IsSlice

func (v *Value) IsSlice() bool

IsSlice returns true if the value is a slice.

func (*Value) IsSpread

func (v *Value) IsSpread() bool

IsSpread returns true if the value is a spread value. Spread values are used to represent the spread operator.

func (*Value) IsString

func (v *Value) IsString() bool

IsString returns true if the value is a string.

func (*Value) Kind

func (v *Value) Kind() reflect.Kind

Kind returns the reflect kind of the value.

func (*Value) Len

func (v *Value) Len() (int, error)

Len returns the length of the value.

func (*Value) LessThan

func (v *Value) LessThan(other *Value) (*Value, error)

LessThan compares two values.

func (*Value) LessThanOrEqual

func (v *Value) LessThanOrEqual(other *Value) (*Value, error)

LessThanOrEqual compares two values.

func (*Value) MapCopy

func (v *Value) MapCopy() (*Value, error)

func (*Value) MapKeyExists

func (v *Value) MapKeyExists(key string) (bool, error)

func (*Value) MapKeyValues

func (v *Value) MapKeyValues() ([]KeyValue, error)

MapKeyValues returns a list of key value pairs in the map.

func (*Value) MapKeys

func (v *Value) MapKeys() ([]string, error)

MapKeys returns a list of keys in the map.

func (*Value) MapLen

func (v *Value) MapLen() (int, error)

MapLen returns the length of the slice.

func (*Value) MarkAsBranch

func (v *Value) MarkAsBranch()

MarkAsBranch marks the value as a branch value.

func (*Value) MarkAsIgnore

func (v *Value) MarkAsIgnore()

MarkAsIgnore marks the value to be ignored.

func (*Value) MarkAsSpread

func (v *Value) MarkAsSpread()

MarkAsSpread marks the value as a spread value. Spread values are used to represent the spread operator.

func (*Value) MetadataValue

func (v *Value) MetadataValue(key string) (any, bool)

MetadataValue returns a metadata value.

func (*Value) Modulo

func (v *Value) Modulo(other *Value) (*Value, error)

Modulo returns the remainder of the division of two values.

func (*Value) Multiply

func (v *Value) Multiply(other *Value) (*Value, error)

Multiply returns the product of the two values.

func (*Value) NotEqual

func (v *Value) NotEqual(other *Value) (*Value, error)

NotEqual compares two values.

func (*Value) RangeMap

func (v *Value) RangeMap(f func(string, *Value) error) error

RangeMap iterates over each key in the map and calls the provided function with the key and value.

func (*Value) RangeSlice

func (v *Value) RangeSlice(f func(int, *Value) error) error

RangeSlice iterates over each item in the slice and calls the provided function.

func (*Value) Set

func (v *Value) Set(newValue *Value) error

Set sets the value of the value.

func (*Value) SetMapKey

func (v *Value) SetMapKey(key string, value *Value) error

SetMapKey sets the value at the specified key in the map.

func (*Value) SetMetadataValue

func (v *Value) SetMetadataValue(key string, val any)

SetMetadataValue sets a metadata value.

func (*Value) SetSliceIndex

func (v *Value) SetSliceIndex(i int, val *Value) error

SetSliceIndex sets the value at the specified index in the slice.

func (*Value) SliceIndexRange

func (v *Value) SliceIndexRange(start, end int) (*Value, error)

SliceIndexRange returns a new slice containing the values between the start and end indexes. Comparable to go's slice[start:end].

func (*Value) SliceLen

func (v *Value) SliceLen() (int, error)

SliceLen returns the length of the slice.

func (*Value) String

func (v *Value) String() string

String returns the value as a formatted string, along with type info.

func (*Value) StringIndexRange

func (v *Value) StringIndexRange(start, end int) (*Value, error)

StringIndexRange returns a new string containing the values between the start and end indexes. Comparable to go's string[start:end].

func (*Value) StringLen

func (v *Value) StringLen() (int, error)

StringLen returns the length of the string.

func (*Value) StringValue

func (v *Value) StringValue() (string, error)

StringValue returns the string value of the Value.

func (*Value) Subtract

func (v *Value) Subtract(other *Value) (*Value, error)

Subtract returns the difference between two values.

func (*Value) Type

func (v *Value) Type() Type

Type returns the type of the value.

func (*Value) UnpackKinds

func (v *Value) UnpackKinds(kinds ...reflect.Kind) *Value

UnpackKinds unpacks the reflect value until it no longer matches the given kinds.

func (*Value) UnpackUntilAddressable

func (v *Value) UnpackUntilAddressable() (*Value, error)

UnpackUntilAddressable unpacks the reflect value until it is addressable.

func (*Value) UnpackUntilKind

func (v *Value) UnpackUntilKind(k reflect.Kind) (*Value, error)

UnpackUntilKind unpacks the reflect value until it matches the given kind.

func (*Value) UnpackUntilKinds

func (v *Value) UnpackUntilKinds(kinds ...reflect.Kind) (*Value, error)

UnpackUntilKinds unpacks the reflect value until it matches the given kind.

func (*Value) UnpackUntilType

func (v *Value) UnpackUntilType(t reflect.Type) (*Value, error)

UnpackUntilType unpacks the reflect value until it matches the given type.

type Values

type Values []*Value

Values represents a list of values.

func (Values) ToSliceValue

func (v Values) ToSliceValue() (*Value, error)

ToSliceValue converts a list of values to a slice value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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