value

package
v0.0.0-...-daaaa79 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RV_ZERO = reflect.Value{}

	EmptyStruct = struct{}{}

	NilValueVal         = NewNilValue()
	BoolValueTrue       = NewBoolValue(true)
	BoolValueFalse      = NewBoolValue(false)
	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))
	NilStructValue      = NewStructValue(nilStruct)
	TimeZeroValue       = NewTimeValue(time.Time{})
	ErrValue            = NewErrorValue("")
)

Functions

func BoolStringVal

func BoolStringVal(sv string) bool

func CanCoerce

func CanCoerce(from, to reflect.Value) bool

func CoerceTo

func CoerceTo(to, itemToConvert reflect.Value) reflect.Value

Given a reflect.Value coerce a 2nd into same type (so we can compare equality)

coerces into limited set of types

int(8,16,32,64), uint(16,32,64,8)   =>    int64
floats                              =>    float64
string                              =>    string
bool                                =>    bool

func Equal

func Equal(itemA, itemB Value) (bool, error)

Equal function

returns bool, error
    first bool for if they are equal
    error if it could not evaluate

func IsBool

func IsBool(sv string) bool

is this boolean string?

func IsNilIsh

func IsNilIsh(v reflect.Value) bool

IsNilish returns true

integers = 0 = true (is nilish)
floats = 0 = true
strings = ""
pointers = nil = true

func ToBool

func ToBool(v reflect.Value) (bool, bool)

toBool convert all reflect.Value-s into bool.

func ToFloat64

func ToFloat64(v reflect.Value) float64

toFloat64 convert all reflect.Value-s into float64.

func ToInt64

func ToInt64(v reflect.Value) (int64, bool)

toInt64 convert all reflect.Value-s into int64.

func ToString

func ToString(v reflect.Value) (string, bool)

ToString convert all reflect.Value-s into string.

func ToStringUnchecked

func ToStringUnchecked(v reflect.Value) string

Types

type BoolValue

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

func NewBoolValue

func NewBoolValue(v bool) BoolValue

func (BoolValue) CanCoerce

func (m BoolValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m BoolValue) Rv() reflect.Value

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 ErrorValue

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

func NewErrorValue

func NewErrorValue(v string) ErrorValue

func (ErrorValue) CanCoerce

func (m ErrorValue) CanCoerce(toRv reflect.Value) bool

func (ErrorValue) Err

func (m ErrorValue) Err() bool

func (ErrorValue) MarshalJSON

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

func (ErrorValue) Nil

func (m ErrorValue) Nil() bool

func (ErrorValue) Rv

func (m ErrorValue) Rv() reflect.Value

func (ErrorValue) ToString

func (m ErrorValue) ToString() string

func (ErrorValue) Type

func (m ErrorValue) Type() ValueType

func (ErrorValue) Val

func (m ErrorValue) Val() string

func (ErrorValue) Value

func (m ErrorValue) Value() interface{}

type IntValue

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

func NewIntValue

func NewIntValue(v int64) IntValue

func (IntValue) CanCoerce

func (m IntValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m IntValue) Rv() reflect.Value

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 MapIntValue

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

func NewMapIntValue

func NewMapIntValue(v map[string]int64) MapIntValue

func (MapIntValue) CanCoerce

func (m MapIntValue) CanCoerce(toRv reflect.Value) bool

func (MapIntValue) Err

func (m MapIntValue) Err() bool

func (MapIntValue) MapFloat

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

func (MapIntValue) MapInt

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

func (MapIntValue) MarshalJSON

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

func (MapIntValue) Nil

func (m MapIntValue) Nil() bool

func (MapIntValue) Rv

func (m MapIntValue) Rv() reflect.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) CanCoerce

func (m MapNumberValue) CanCoerce(toRv reflect.Value) bool

func (MapNumberValue) Err

func (m MapNumberValue) Err() bool

func (MapNumberValue) MapInt

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

func (MapNumberValue) MarshalJSON

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

func (MapNumberValue) Nil

func (m MapNumberValue) Nil() bool

func (MapNumberValue) Rv

func (m MapNumberValue) Rv() reflect.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) CanCoerce

func (m MapStringValue) CanCoerce(toRv reflect.Value) bool

func (MapStringValue) Err

func (m MapStringValue) Err() bool

func (MapStringValue) MarshalJSON

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

func (MapStringValue) Nil

func (m MapStringValue) Nil() bool

func (MapStringValue) Rv

func (m MapStringValue) Rv() reflect.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 MapValue

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

func NewMapValue

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

func (MapValue) CanCoerce

func (m MapValue) CanCoerce(toRv reflect.Value) bool

func (MapValue) Err

func (m MapValue) Err() bool

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) MarshalJSON

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

func (MapValue) Nil

func (m MapValue) Nil() bool

func (MapValue) Rv

func (m MapValue) Rv() reflect.Value

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) CanCoerce

func (m NilValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m NilValue) Rv() reflect.Value

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 NewNumberValue

func NewNumberValue(v float64) NumberValue

func (NumberValue) CanCoerce

func (m NumberValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m NumberValue) Rv() reflect.Value

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 SliceValue

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

func NewSliceValues

func NewSliceValues(v []Value) 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) Rv

func (m SliceValue) Rv() reflect.Value

func (SliceValue) Type

func (m SliceValue) Type() ValueType

func (SliceValue) Val

func (m SliceValue) Val() []Value

func (SliceValue) Value

func (m SliceValue) Value() interface{}

type StringValue

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

func NewStringValue

func NewStringValue(v string) StringValue

func (StringValue) CanCoerce

func (m StringValue) CanCoerce(input reflect.Value) bool

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) Rv

func (m StringValue) Rv() reflect.Value

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) CanCoerce

func (m StringsValue) CanCoerce(boolRv reflect.Value) bool

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) Rv

func (m StringsValue) Rv() reflect.Value

func (StringsValue) Set

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

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) CanCoerce

func (m StructValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m StructValue) Rv() reflect.Value

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(t time.Time) TimeValue

func (TimeValue) CanCoerce

func (m TimeValue) CanCoerce(toRv reflect.Value) bool

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) Rv

func (m TimeValue) Rv() reflect.Value

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?  ie empty string?  or nil struct, etc
	Nil() bool
	// Is this an error, or unable to evaluate from Vm?
	Err() bool
	Value() interface{}
	Rv() reflect.Value
	ToString() string
	Type() ValueType
}

func NewValue

func NewValue(goVal interface{}) Value

Create a new Value type with native go value

func ToValue

func ToValue(v interface{}) (Value, error)

Coerce interface{} values (string,int,int64, float, []byte) into appropriate

vm.Value type

int(8,16,32,64), uint(16,32,64,8)   =>    IntValue
floats                              =>    NumberValue
string                              =>    StringValue
bool                                =>    BoolValue

TODO:

[]byte, json.RawMessage,
struct{}
time.Time

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
	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
	SliceValueType ValueType = 40
	StructType     ValueType = 50
)

func ValueTypeFromRT

func ValueTypeFromRT(rt reflect.Type) ValueType

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