value

package
v0.0.0-...-7e2ea95 Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Value package defines the core value types (string, int, etc) for the qlbridge package, mostly used to provide common interfaces instead of reflection for virtual machine.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConversion             = fmt.Errorf("Error converting type")
	ErrConversionNotSupported = fmt.Errorf("Unsupported conversion")
)
View Source
var (
	EmptyStruct = struct{}{}

	NilValueVal         = NewNilValue()
	BoolValueTrue       = BoolValue{/* contains filtered or unexported fields */}
	BoolValueFalse      = BoolValue{/* contains filtered or unexported fields */}
	NumberNaNValue      = NewNumberValue(math.NaN())
	EmptyStringValue    = NewStringValue("")
	EmptyStringsValue   = NewStringsValue(nil)
	EmptyMapValue       = NewMapValue(nil)
	EmptyMapStringValue = NewMapStringValue(make(map[string]string))
	EmptyMapIntValue    = NewMapIntValue(make(map[string]int64))
	EmptyMapNumberValue = NewMapNumberValue(make(map[string]float64))
	EmptyMapTimeValue   = NewMapTimeValue(make(map[string]time.Time))
	EmptyMapBoolValue   = NewMapBoolValue(make(map[string]bool))
	NilStructValue      = NewStructValue(nilStruct)
	TimeZeroValue       = NewTimeValue(time.Time{})
	ErrValue            = NewErrorValue(fmt.Errorf(""))
)

Functions

func BoolStringVal

func BoolStringVal(sv string) bool

func Equal

func Equal(l, r Value) (bool, error)

Equal function compares equality after detecting type. error if it could not evaluate

func IsBool

func IsBool(sv string) bool

is this boolean string?

func StringToFloat64

func StringToFloat64(s string) (float64, bool)

StringToFloat64 converts a string to a float includes replacement of $ and other monetary format identifiers. May return math.NaN

func StringToTimeAnchor

func StringToTimeAnchor(val string, anchor time.Time) (time.Time, bool)

StringToTimeAnchor Convert a string type to a time if possible. If "now-3d" then use date-anchoring ie if prefix = 'now'.

func ValueToBool

func ValueToBool(val Value) (bool, bool)

ValueToBool Convert a value type to a bool if possible

func ValueToFloat64

func ValueToFloat64(val Value) (float64, bool)

ValueToFloat64 Convert a value type to a float64 if possible

func ValueToInt

func ValueToInt(val Value) (int, bool)

ValueToInt Convert a value type to a int if possible

func ValueToInt64

func ValueToInt64(val Value) (int64, bool)

ValueToInt64 Convert a value type to a int64 if possible

func ValueToString

func ValueToString(val Value) (string, bool)

ValueToString convert all scalar values to their go string.

func ValueToStrings

func ValueToStrings(val Value) ([]string, bool)

ValueToStrings convert all scalar values to their go []string.

func ValueToTime

func ValueToTime(val Value) (time.Time, bool)

ValueToTime Convert a value type to a time if possible

func ValueToTimeAnchor

func ValueToTimeAnchor(val Value, anchor time.Time) (time.Time, bool)

ValueToTimeAnchor given a value, and a time anchor, conver to time. use "now-3d" anchoring if has prefix "now".

Types

type BoolValue

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

func NewBoolValue

func NewBoolValue(v bool) BoolValue

func (BoolValue) Err

func (m BoolValue) Err() bool

func (BoolValue) MarshalJSON

func (m BoolValue) MarshalJSON() ([]byte, error)

func (BoolValue) Nil

func (m BoolValue) Nil() bool

func (BoolValue) ToString

func (m BoolValue) ToString() string

func (BoolValue) Type

func (m BoolValue) Type() ValueType

func (BoolValue) Val

func (m BoolValue) Val() bool

func (BoolValue) Value

func (m BoolValue) Value() interface{}

type ByteSliceValue

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

func NewByteSliceValue

func NewByteSliceValue(v []byte) ByteSliceValue

func (ByteSliceValue) Err

func (m ByteSliceValue) Err() bool

func (ByteSliceValue) Len

func (m ByteSliceValue) Len() int

func (ByteSliceValue) MarshalJSON

func (m ByteSliceValue) MarshalJSON() ([]byte, error)

func (ByteSliceValue) Nil

func (m ByteSliceValue) Nil() bool

func (ByteSliceValue) ToString

func (m ByteSliceValue) ToString() string

func (ByteSliceValue) Type

func (m ByteSliceValue) Type() ValueType

func (ByteSliceValue) Val

func (m ByteSliceValue) Val() []byte

func (ByteSliceValue) Value

func (m ByteSliceValue) Value() interface{}

type ErrorValue

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

func NewErrorValue

func NewErrorValue(v error) ErrorValue

func NewErrorValuef

func NewErrorValuef(v string, args ...interface{}) ErrorValue

func (ErrorValue) Err

func (m ErrorValue) Err() bool

func (ErrorValue) Error

func (m ErrorValue) Error() string

ErrorValues implement Go's error interface so they can easily cross the VM/Go boundary.

func (ErrorValue) MarshalJSON

func (m ErrorValue) MarshalJSON() ([]byte, error)

func (ErrorValue) Nil

func (m ErrorValue) Nil() bool

func (ErrorValue) ToString

func (m ErrorValue) ToString() string

func (ErrorValue) Type

func (m ErrorValue) Type() ValueType

func (ErrorValue) Val

func (m ErrorValue) Val() error

func (ErrorValue) Value

func (m ErrorValue) Value() interface{}

type IntValue

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

func NewIntNil

func NewIntNil() IntValue

func NewIntValue

func NewIntValue(v int64) IntValue

func (IntValue) Err

func (m IntValue) Err() bool

func (IntValue) Float

func (m IntValue) Float() float64

func (IntValue) Int

func (m IntValue) Int() int64

func (IntValue) MarshalJSON

func (m IntValue) MarshalJSON() ([]byte, error)

func (IntValue) Nil

func (m IntValue) Nil() bool

func (IntValue) NumberValue

func (m IntValue) NumberValue() NumberValue

func (IntValue) ToString

func (m IntValue) ToString() string

func (IntValue) Type

func (m IntValue) Type() ValueType

func (IntValue) Val

func (m IntValue) Val() int64

func (IntValue) Value

func (m IntValue) Value() interface{}

type JsonValue

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

func NewJsonValue

func NewJsonValue(v json.RawMessage) JsonValue

func (JsonValue) Err

func (m JsonValue) Err() bool

func (JsonValue) MarshalJSON

func (m JsonValue) MarshalJSON() ([]byte, error)

func (JsonValue) Nil

func (m JsonValue) Nil() bool

func (JsonValue) ToString

func (m JsonValue) ToString() string

func (JsonValue) Type

func (m JsonValue) Type() ValueType

func (JsonValue) Val

func (m JsonValue) Val() interface{}

func (JsonValue) Value

func (m JsonValue) Value() interface{}

type Map

type Map interface {
	json.Marshaler
	Len() int
	MapValue() MapValue
	Get(key string) (Value, bool)
}

Map interface

type MapBoolValue

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

func NewMapBoolValue

func NewMapBoolValue(v map[string]bool) MapBoolValue

func (MapBoolValue) Err

func (m MapBoolValue) Err() bool

func (MapBoolValue) Get

func (m MapBoolValue) Get(key string) (Value, bool)

func (MapBoolValue) Len

func (m MapBoolValue) Len() int

func (MapBoolValue) MapValue

func (m MapBoolValue) MapValue() MapValue

func (MapBoolValue) MarshalJSON

func (m MapBoolValue) MarshalJSON() ([]byte, error)

func (MapBoolValue) Nil

func (m MapBoolValue) Nil() bool

func (MapBoolValue) SliceValue

func (m MapBoolValue) SliceValue() []Value

func (MapBoolValue) ToString

func (m MapBoolValue) ToString() string

func (MapBoolValue) Type

func (m MapBoolValue) Type() ValueType

func (MapBoolValue) Val

func (m MapBoolValue) Val() map[string]bool

func (MapBoolValue) Value

func (m MapBoolValue) Value() interface{}

type MapIntValue

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

func NewMapIntValue

func NewMapIntValue(v map[string]int64) MapIntValue

func (MapIntValue) Err

func (m MapIntValue) Err() bool

func (MapIntValue) Get

func (m MapIntValue) Get(key string) (Value, bool)

func (MapIntValue) Len

func (m MapIntValue) Len() int

func (MapIntValue) MapFloat

func (m MapIntValue) MapFloat() map[string]float64

func (MapIntValue) MapInt

func (m MapIntValue) MapInt() map[string]int64

func (MapIntValue) MapValue

func (m MapIntValue) MapValue() MapValue

func (MapIntValue) MarshalJSON

func (m MapIntValue) MarshalJSON() ([]byte, error)

func (MapIntValue) Nil

func (m MapIntValue) Nil() bool

func (MapIntValue) SliceValue

func (m MapIntValue) SliceValue() []Value

func (MapIntValue) ToString

func (m MapIntValue) ToString() string

func (MapIntValue) Type

func (m MapIntValue) Type() ValueType

func (MapIntValue) Val

func (m MapIntValue) Val() map[string]int64

func (MapIntValue) Value

func (m MapIntValue) Value() interface{}

type MapNumberValue

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

func NewMapNumberValue

func NewMapNumberValue(v map[string]float64) MapNumberValue

func (MapNumberValue) Err

func (m MapNumberValue) Err() bool

func (MapNumberValue) Get

func (m MapNumberValue) Get(key string) (Value, bool)

func (MapNumberValue) Len

func (m MapNumberValue) Len() int

func (MapNumberValue) MapInt

func (m MapNumberValue) MapInt() map[string]int64

func (MapNumberValue) MapValue

func (m MapNumberValue) MapValue() MapValue

func (MapNumberValue) MarshalJSON

func (m MapNumberValue) MarshalJSON() ([]byte, error)

func (MapNumberValue) Nil

func (m MapNumberValue) Nil() bool

func (MapNumberValue) SliceValue

func (m MapNumberValue) SliceValue() []Value

func (MapNumberValue) ToString

func (m MapNumberValue) ToString() string

func (MapNumberValue) Type

func (m MapNumberValue) Type() ValueType

func (MapNumberValue) Val

func (m MapNumberValue) Val() map[string]float64

func (MapNumberValue) Value

func (m MapNumberValue) Value() interface{}

type MapStringValue

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

func NewMapStringValue

func NewMapStringValue(v map[string]string) MapStringValue

func (MapStringValue) Err

func (m MapStringValue) Err() bool

func (MapStringValue) Get

func (m MapStringValue) Get(key string) (Value, bool)

func (MapStringValue) Len

func (m MapStringValue) Len() int

func (MapStringValue) MapBool

func (m MapStringValue) MapBool() MapBoolValue

func (MapStringValue) MapInt

func (m MapStringValue) MapInt() MapIntValue

func (MapStringValue) MapNumber

func (m MapStringValue) MapNumber() MapNumberValue

func (MapStringValue) MapValue

func (m MapStringValue) MapValue() MapValue

func (MapStringValue) MarshalJSON

func (m MapStringValue) MarshalJSON() ([]byte, error)

func (MapStringValue) Nil

func (m MapStringValue) Nil() bool

func (MapStringValue) SliceValue

func (m MapStringValue) SliceValue() []Value

func (MapStringValue) ToString

func (m MapStringValue) ToString() string

func (MapStringValue) Type

func (m MapStringValue) Type() ValueType

func (MapStringValue) Val

func (m MapStringValue) Val() map[string]string

func (MapStringValue) Value

func (m MapStringValue) Value() interface{}

type MapTimeValue

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

func NewMapTimeValue

func NewMapTimeValue(v map[string]time.Time) MapTimeValue

func (MapTimeValue) Err

func (m MapTimeValue) Err() bool

func (MapTimeValue) Get

func (m MapTimeValue) Get(key string) (Value, bool)

func (MapTimeValue) Len

func (m MapTimeValue) Len() int

func (MapTimeValue) MapInt

func (m MapTimeValue) MapInt() map[string]int64

func (MapTimeValue) MapValue

func (m MapTimeValue) MapValue() MapValue

func (MapTimeValue) MarshalJSON

func (m MapTimeValue) MarshalJSON() ([]byte, error)

func (MapTimeValue) Nil

func (m MapTimeValue) Nil() bool

func (MapTimeValue) ToString

func (m MapTimeValue) ToString() string

func (MapTimeValue) Type

func (m MapTimeValue) Type() ValueType

func (MapTimeValue) Val

func (m MapTimeValue) Val() map[string]time.Time

func (MapTimeValue) Value

func (m MapTimeValue) Value() interface{}

type MapValue

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

func NewMapValue

func NewMapValue(v map[string]interface{}) MapValue

func (MapValue) Err

func (m MapValue) Err() bool

func (MapValue) Get

func (m MapValue) Get(key string) (Value, bool)

func (MapValue) Len

func (m MapValue) Len() int

func (MapValue) MapFloat

func (m MapValue) MapFloat() map[string]float64

func (MapValue) MapInt

func (m MapValue) MapInt() map[string]int64

func (MapValue) MapString

func (m MapValue) MapString() map[string]string

func (MapValue) MapTime

func (m MapValue) MapTime() MapTimeValue

func (MapValue) MapValue

func (m MapValue) MapValue() MapValue

func (MapValue) MarshalJSON

func (m MapValue) MarshalJSON() ([]byte, error)

func (MapValue) Nil

func (m MapValue) Nil() bool

func (MapValue) ToString

func (m MapValue) ToString() string

func (MapValue) Type

func (m MapValue) Type() ValueType

func (MapValue) Val

func (m MapValue) Val() map[string]Value

func (MapValue) Value

func (m MapValue) Value() interface{}

type NilValue

type NilValue struct{}

func NewNilValue

func NewNilValue() NilValue

func (NilValue) Err

func (m NilValue) Err() bool

func (NilValue) MarshalJSON

func (m NilValue) MarshalJSON() ([]byte, error)

func (NilValue) Nil

func (m NilValue) Nil() bool

func (NilValue) ToString

func (m NilValue) ToString() string

func (NilValue) Type

func (m NilValue) Type() ValueType

func (NilValue) Val

func (m NilValue) Val() interface{}

func (NilValue) Value

func (m NilValue) Value() interface{}

type NumberValue

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

func NewNumberNil

func NewNumberNil() NumberValue

func NewNumberValue

func NewNumberValue(v float64) NumberValue

func (NumberValue) Err

func (m NumberValue) Err() bool

func (NumberValue) Float

func (m NumberValue) Float() float64

func (NumberValue) Int

func (m NumberValue) Int() int64

func (NumberValue) MarshalJSON

func (m NumberValue) MarshalJSON() ([]byte, error)

func (NumberValue) Nil

func (m NumberValue) Nil() bool

func (NumberValue) ToString

func (m NumberValue) ToString() string

func (NumberValue) Type

func (m NumberValue) Type() ValueType

func (NumberValue) Val

func (m NumberValue) Val() float64

func (NumberValue) Value

func (m NumberValue) Value() interface{}

type NumericValue

type NumericValue interface {
	Float() float64
	Int() int64
}

Certain types are Numeric (Ints, Time, Number)

type Slice

type Slice interface {
	SliceValue() []Value
	Len() int
	json.Marshaler
}

Slices can always return a []Value representation and is meant to be used when iterating over all items in a non-scalar value. Maps return their keys as a slice.

type SliceValue

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

func NewSliceValues

func NewSliceValues(v []Value) SliceValue

func NewSliceValuesNative

func NewSliceValuesNative(iv []interface{}) SliceValue

func (*SliceValue) Append

func (m *SliceValue) Append(v Value)

func (SliceValue) Err

func (m SliceValue) Err() bool

func (SliceValue) Len

func (m SliceValue) Len() int

func (SliceValue) MarshalJSON

func (m SliceValue) MarshalJSON() ([]byte, error)

func (SliceValue) Nil

func (m SliceValue) Nil() bool

func (SliceValue) SliceValue

func (m SliceValue) SliceValue() []Value

func (SliceValue) ToString

func (m SliceValue) ToString() string

func (SliceValue) Type

func (m SliceValue) Type() ValueType

func (SliceValue) Val

func (m SliceValue) Val() []Value

func (SliceValue) Value

func (m SliceValue) Value() interface{}

func (SliceValue) Values

func (m SliceValue) Values() []interface{}

type StringValue

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

func NewStringValue

func NewStringValue(v string) StringValue

func (StringValue) Err

func (m StringValue) Err() bool

func (StringValue) IntValue

func (m StringValue) IntValue() IntValue

func (StringValue) MarshalJSON

func (m StringValue) MarshalJSON() ([]byte, error)

func (StringValue) Nil

func (m StringValue) Nil() bool

func (StringValue) NumberValue

func (m StringValue) NumberValue() NumberValue

func (StringValue) StringsValue

func (m StringValue) StringsValue() StringsValue

func (StringValue) ToString

func (m StringValue) ToString() string

func (StringValue) Type

func (m StringValue) Type() ValueType

func (StringValue) Val

func (m StringValue) Val() string

func (StringValue) Value

func (m StringValue) Value() interface{}

type StringsValue

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

func NewStringsValue

func NewStringsValue(v []string) StringsValue

func (*StringsValue) Append

func (m *StringsValue) Append(sv string)

func (StringsValue) Err

func (m StringsValue) Err() bool

func (StringsValue) IntValue

func (m StringsValue) IntValue() IntValue

func (StringsValue) Len

func (m StringsValue) Len() int

func (StringsValue) MarshalJSON

func (m StringsValue) MarshalJSON() ([]byte, error)

func (StringsValue) Nil

func (m StringsValue) Nil() bool

func (StringsValue) NumberValue

func (m StringsValue) NumberValue() NumberValue

func (StringsValue) Set

func (m StringsValue) Set() map[string]struct{}

func (StringsValue) SliceValue

func (m StringsValue) SliceValue() []Value

func (StringsValue) Strings

func (m StringsValue) Strings() []string

func (StringsValue) ToString

func (m StringsValue) ToString() string

func (StringsValue) Type

func (m StringsValue) Type() ValueType

func (StringsValue) Val

func (m StringsValue) Val() []string

func (StringsValue) Value

func (m StringsValue) Value() interface{}

type StructValue

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

func NewStructValue

func NewStructValue(v interface{}) StructValue

func (StructValue) Err

func (m StructValue) Err() bool

func (StructValue) MarshalJSON

func (m StructValue) MarshalJSON() ([]byte, error)

func (StructValue) Nil

func (m StructValue) Nil() bool

func (StructValue) ToString

func (m StructValue) ToString() string

func (StructValue) Type

func (m StructValue) Type() ValueType

func (StructValue) Val

func (m StructValue) Val() interface{}

func (StructValue) Value

func (m StructValue) Value() interface{}

type TimeValue

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

func NewTimeValue

func NewTimeValue(v time.Time) TimeValue

func (TimeValue) Err

func (m TimeValue) Err() bool

func (TimeValue) Float

func (m TimeValue) Float() float64

func (TimeValue) Int

func (m TimeValue) Int() int64

func (TimeValue) MarshalJSON

func (m TimeValue) MarshalJSON() ([]byte, error)

func (TimeValue) Nil

func (m TimeValue) Nil() bool

func (TimeValue) Time

func (m TimeValue) Time() time.Time

func (TimeValue) ToString

func (m TimeValue) ToString() string

func (TimeValue) Type

func (m TimeValue) Type() ValueType

func (TimeValue) Val

func (m TimeValue) Val() time.Time

func (TimeValue) Value

func (m TimeValue) Value() interface{}

type Value

type Value interface {
	// Is this a nil/empty?
	// empty string counts as nil, empty slices/maps, nil structs.
	Nil() bool
	// Is this an error, or unable to evaluate from Vm?
	Err() bool
	Value() interface{}
	ToString() string
	Type() ValueType
}

func Cast

func Cast(valType ValueType, val Value) (Value, error)

Cast a value to given value type

func NewValue

func NewValue(goVal interface{}) Value

NewValue creates a new Value type from a native Go value.

Defaults to StructValue for unknown types.

type ValueType

type ValueType uint8

This is the DataType system, ie string, int, etc

const (
	// Enum values for Type system, DO NOT CHANGE the numbers, do not use iota
	NilType            ValueType = 0
	ErrorType          ValueType = 1
	UnknownType        ValueType = 2
	ValueInterfaceType ValueType = 3 // Is of type Value Interface, ie unknown
	NumberType         ValueType = 10
	IntType            ValueType = 11
	BoolType           ValueType = 12
	TimeType           ValueType = 13
	ByteSliceType      ValueType = 14
	StringType         ValueType = 20
	StringsType        ValueType = 21
	MapValueType       ValueType = 30
	MapIntType         ValueType = 31
	MapStringType      ValueType = 32
	MapNumberType      ValueType = 33
	MapBoolType        ValueType = 34
	MapTimeType        ValueType = 35
	SliceValueType     ValueType = 40
	StructType         ValueType = 50
	JsonType           ValueType = 51
)

func ValueFromString

func ValueFromString(vt string) ValueType

ValueFromString Given a string, convert to valuetype

func ValueTypeFromString

func ValueTypeFromString(val string) ValueType

ValueTypeFromString take a string value and infer valuetype Will infer based on the following rules: - If parseable as int, will be int - if not above, and parse bool, is bool - if not above, and parse float, float - if not above, and parse date, date - else string

func ValueTypeFromStringAll

func ValueTypeFromStringAll(val string) ValueType

ValueTypeFromStringAll take a string value and infer valuetype adding the valid type JSON preferred over raw string.

Will infer based on the following rules: - If parseable as int, will be int - if not above, and parse bool, is bool - if not above, and parse float, float - if not above, and parse date, date - if not above, and appears to be json (doesn't have to be valid) - else string

func (ValueType) IsMap

func (m ValueType) IsMap() bool

func (ValueType) IsNumeric

func (m ValueType) IsNumeric() bool

func (ValueType) IsSlice

func (m ValueType) IsSlice() bool

func (ValueType) String

func (m ValueType) String() string

Jump to

Keyboard shortcuts

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