expr

package
v0.0.0-...-06831c0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Example (Abs)
eval(`abs(-3.14)`, nil)
Output:

3.14
Example (Average)
eval(`average(1, 2, 3, "foo", 10)`, 10.4)
Output:

4
Example (Base64encode)
eval(`base64encode("foo bar baz_test")`, nil)
Output:

Zm9vIGJhciBiYXpfdGVzdA==
Example (Camelize)
eval(`camelize("foo bar baz_test")`, nil)
Output:

fooBarBaz_test
Example (CastFloatToInt)
eval(`int("42.690")`, nil)
Output:

0
Example (CastStringNumberToInt)
eval(`int("42690")`, nil)
Output:

42690
Example (CastStringToInt)
eval(`int("abc")`, nil)
Output:

0
Example (Ceil)
eval(`ceil(3.14)`, nil)
Output:

4
Example (Earliest)
eval(`earliest(hgp, wfa)`, exampleTimeParams)
Output:

1929-01-06 00:00:00 +0000 UTC
Example (Filter_kv)
var (
	kv = &KV{value: map[string]string{
		"k1": "v1",
		"k2": "v2",
	}}
	p = map[string]interface{}{
		"kv":   kv,
		"key1": "k1",
		"key2": "k3",
	}
)

eval(`filter(kv, key1, key2)`, p)
fmt.Printf("\nOriginal KV should be %v", kv.value)
Output:

map[k1:v1]
Original KV should be map[k1:v1 k2:v2]
Example (Filter_kvv)
var (
	kvv = &KVV{value: map[string][]string{
		"k1": {"v1"},
		"k2": {"v2"},
	}}
	p = map[string]interface{}{
		"kv":   kvv,
		"key1": "k1",
		"key2": "k3",
	}
)

eval(`filter(kv, key1, key2)`, p)
fmt.Printf("\nOriginal KVV should be %v", kvv.value)
Output:

map[k1:[v1]]
Original KVV should be map[k1:[v1] k2:[v2]]
Example (Filter_vars)
var (
	p = map[string]interface{}{
		"vars": &Vars{value: map[string]TypedValue{
			"k1": &String{value: "v1"},
			"k5": &String{value: "v5"},
		}},
		"key1": "k1",
		"key2": "k3",
		"key3": "k5",
	}
)

eval(`toJSON(filter(vars, key1, key2, key3))`, p)
Output:

{"k1":{"@value":"v1","@type":"String"},"k5":{"@value":"v5","@type":"String"}}
Example (Floor)
eval(`floor(3.14)`, nil)
Output:

3
Example (HasPrefix)
eval(`hasPrefix("foo bar", "foo ")`, nil)
Output:

true
Example (HasSubstring_caseI)
eval(`hasSubstring("foo BAR", "o b", false)`, nil)
Output:

true
Example (HasSubstring_caseS)
eval(`hasSubstring("foo BAR", "o b", true)`, nil)
Output:

false
Example (HasSuffix)
eval(`hasSuffix("foo bar", "ar")`, nil)
Output:

true
Example (IsEmail)
eval(`isUrl("example.user+valid@example.tld")`, nil)
Output:

true
Example (IsLeapYear)
eval(`isLeapYear(ghd)`, exampleTimeParams)
Output:

false
Example (IsUrl)
eval(`isUrl("http:/example.tld")`, nil)
Output:

false
Example (IsWeekDay)
eval(`isWeekDay(ghd)`, exampleTimeParams)
Output:

true
Example (Join)
eval(`join(exploded, ",")`, map[string][]string{"exploded": {"One", "two", "three"}})
Output:

One,two,three
Example (Kv_toJSON)
var (
	p = map[string]interface{}{
		"kv": Must(NewKV(
			&KV{value: map[string]string{
				"k1": "v1",
				"k2": "v2",
			}},
		)),
	}
)

eval(`toJSON(kv)`, p)
Output:

{"k1":"v1","k2":"v2"}
Example (Latest)
eval(`latest(ghd, wfa)`, exampleTimeParams)
Output:

1993-02-02 06:00:00 -0500 -0500
Example (Ln)
eval(`pow(2, 3)`, nil)
Output:

8
Example (Log)
eval(`log(100)`, nil)
Output:

2
Example (Longest)
eval(`longest("foo", "foobar")`, nil)
Output:

foobar
Example (Match)
eval(`match("foo bar baz_test", "^foo\\s.*$")`, nil)
Output:

true
Example (Max)
eval(`max(2, 1, 3)`, nil)
Output:

3
Example (Merge_kv)
var (
	kv = &KV{}
	p  = map[string]interface{}{
		"kv": kv,
		"foo": &KV{value: map[string]string{
			"k1": "v1",
		}},
		"bar": &KV{value: map[string]string{
			"k2": "v2",
		}},
	}
)

eval(`merge(kv, foo, bar)`, p)
fmt.Printf("\nOriginal KV should be %v", kv.value)
Output:

map[k1:v1 k2:v2]
Original KV should be map[]
Example (Merge_kvv)
var (
	kvv = &KVV{}
	p   = map[string]interface{}{
		"kvv": kvv,
		"foo": &KVV{value: map[string][]string{
			"k1": {"v1"},
		}},
		"bar": &KVV{value: map[string][]string{
			"k1": {"v11"},
			"k2": {"v2"},
		}},
	}
)

eval(`merge(kvv, foo, bar)`, p)
fmt.Printf("\nOriginal KVV should be %v", kvv.value)
Output:

map[k1:[v1 v11] k2:[v2]]
Original KVV should be map[]
Example (Merge_vars)
var (
	p = map[string]interface{}{
		"vars": &Vars{},
		"foo": &Vars{value: map[string]TypedValue{
			"k1": &String{value: "v1"},
		}},
		"bar": &Vars{value: map[string]TypedValue{
			"k2": &String{value: "v2"},
		}},
	}
)

eval(`toJSON(merge(foo, bar))`, p)
Output:

{"k1":{"@value":"v1","@type":"String"},"k2":{"@value":"v2","@type":"String"}}
Example (Min)
eval(`min(2, 1, 3)`, nil)
Output:

1
Example (ModDate)
eval(`modDate(ghd, "5")`, exampleTimeParams)
Output:

1993-02-07 06:00:00 -0500 -0500
Example (ModMonth)
eval(`modMonth(ghd, "1")`, exampleTimeParams)
Output:

1993-03-02 06:00:00 -0500 -0500
Example (ModTime)
eval(`modTime(ghd, "+30m")`, exampleTimeParams)
Output:

1993-02-02 06:30:00 -0500 -0500
Example (ModWeek)
eval(`modWeek(ghd, "1")`, exampleTimeParams)
Output:

1993-02-09 06:00:00 -0500 -0500
Example (ModYear)
eval(`modYear(ghd, "5")`, exampleTimeParams)
Output:

1998-02-02 06:00:00 -0500 -0500
Example (Omit_kv)
var (
	kv = &KV{value: map[string]string{
		"k1": "v1",
		"k2": "v2",
		"k3": "v3",
	}}
	p = map[string]interface{}{
		"kv":   kv,
		"key1": "k1",
		"key2": "k3",
	}
)

eval(`omit(kv, key1, key2)`, p)
fmt.Printf("\nOriginal KV should be %v", kv.value)
Output:

map[k2:v2]
Original KV should be map[k1:v1 k2:v2 k3:v3]
Example (Omit_kvv)
var (
	kvv = &KVV{value: map[string][]string{
		"k1": {"v1"},
		"k2": {"v2"},
		"k3": {"v3"},
	}}
	p = map[string]interface{}{
		"kvv":  kvv,
		"key1": "k1",
		"key2": "k3",
	}
)

eval(`omit(kvv, key1, key2)`, p)
fmt.Printf("\nOriginal KVV should be %v", kvv.value)
Output:

map[k2:[v2]]
Original KVV should be map[k1:[v1] k2:[v2] k3:[v3]]
Example (Omit_vars)
var (
	p = map[string]interface{}{
		"vars": &Vars{value: map[string]TypedValue{
			"k1": &String{value: "v1"},
			"k2": &String{value: "v2"},
			"k3": &String{value: "v3"},
		}},
		"key1": "k1",
		"key2": "k3",
	}
)

eval(`toJSON(omit(vars, key1, key2))`, p)
Output:

{"k2":{"@value":"v2","@type":"String"}}
Example (ParseDate)
eval(`date("1993-02-02 06:00:00+01:10")`, nil)
Output:

1993-02-02 06:00:00 +0110 +0110
Example (ParseDuration)
eval(`parseDuration("2h")`, nil)
Output:

2h0m0s
Example (ParseISODate)
eval(`date("1993-02-02T06:00:00-05:00")`, nil)
Output:

1993-02-02 06:00:00 -0500 -0500
Example (Pop_float)
eval(`pop(floatArr)`, vals)
Output:

69.42
Example (Pop_int)
eval(`pop(intArr)`, vals)
Output:

<nil>
Example (Pop_string)
eval(`pop(stringArr)`, vals)
Output:

first
Example (Push_bool)
eval(`push(boolArr, boolVal)`, vals)
Output:

[true true false false]
Example (Push_float)
eval(`push(floatArr, 3.14)`, vals)
Output:

[69.42 3.14]
Example (Push_int)
eval(`push(intArr, intVal)`, vals)
Output:

[42]
Example (Push_string)
eval(`push(stringArr, stringVal)`, vals)
Output:

[first foobar]
Example (RandomWithSingleInput)
eval(`max(random(6), 7)`, nil)
Output:

7
Example (RandomWithTwoInput)
eval(`min(random(2, 6), 1)`, nil)
Output:

1
Example (Repeat)
eval(`repeat("duran ", c)`, map[string]interface{}{"c": 2})
Output:

duran duran
Example (Replace_all)
eval(`replace("foobar baz", "ba", "BA", c)`, map[string]interface{}{"c": -1})
Output:

fooBAr BAz
Example (Replace_first)
eval(`replace("foobar baz", "ba", "BA", c)`, map[string]interface{}{"c": 1})
Output:

fooBAr baz
Example (Round)
eval(`round(3.14,1)`, nil)
Output:

3.1
Example (Set_kv)
var (
	kv = &KV{}
	p  = map[string]interface{}{
		"kv":    kv,
		"key":   "k1",
		"value": Must(NewString("v11")),
	}
)

eval(`set(kv, key, value)`, p)
fmt.Printf("\nOriginal KV should be %v", kv.value)
Output:

map[k1:v11]
Original KV should be map[]
Example (Set_kvv)
var (
	kvv = &KVV{}
	p   = map[string]interface{}{
		"kvv":   kvv,
		"key":   "foo",
		"value": Must(NewString("bar")),
	}
)

eval(`set(kvv, key, value)`, p)
fmt.Printf("\nOriginal KVV should be %v", kvv.value)
Output:

map[foo:[bar]]
Original KVV should be map[]
Example (Set_vars)
var (
	p = map[string]interface{}{
		"vars":  &Vars{},
		"key":   "foo",
		"value": &String{value: "foo"},
	}
)

eval(`toJSON(set(vars, key, value))`, p)
Output:

{"foo":{"@value":"foo","@type":"String"}}
Example (Shorten_char)
eval(`shorten("foo bar 1337, this is. test one - or three", "char", c)`, map[string]int{"c": 22})
Output:

foo bar 1337, this is …
Example (Shorten_word)
eval(`shorten("foo bar 1337, this is. test one - or three", "word", c)`, map[string]int{"c": 3})
Output:

foo bar 1337 …
Example (Shortest)
eval(`shortest("foo", "foobar")`, nil)
Output:

foo
Example (SimpleExpression)
eval(`40 + 2`, nil)
Output:

42
Example (Snakify)
eval(`snakify("foo bar baz_test")`, nil)
Output:

foo_bar_baz_test
Example (Sort_string_asc)
eval(`sort(strArr, false)`, vals)
Output:

[1 2 3 5]
Example (Sort_string_desc)
eval(`sort(strArr, true)`, vals)
Output:

[5 3 2 1]
Example (Split)
eval(`split("This will be split in:2-parts", ":")`, nil)
Output:

[This will be split in 2-parts]
Example (Sqrt)
eval(`sqrt(16)`, nil)
Output:

4
Example (Strftime)
eval(`strftime(ghd, "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
Output:

1993-02-02T06:00:00
Example (StrftimeWithModTime)
eval(`strftime(modTime(ghd, "+30m"), "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
Output:

1993-02-02T06:30:00
Example (StrftimeWithStringValue)
eval(`strftime("1993-02-02T06:30:00", "%Y-%m-%dT%H:%M:%S")`, exampleTimeParams)
Output:

1993-02-02T06:30:00
Example (Sub)
eval(`sub(hgp, ghd)`, exampleTimeParams)
Output:

321627600000
Example (SubErrorCheck)
eval(`sub(ghd, hgp)`, exampleTimeParams)
Output:

error: can not evaluate sub(ghd, hgp): expecting 2nd input to be less than 1st input
Example (Substring)
eval(`substring("foo bar baz_test", start, end)`, map[string]interface{}{"start": 2, "end": -1})
Output:

o bar baz_test
Example (Substring_endOverflow)
eval(`substring("foo bar baz_test", start, end)`, map[string]interface{}{"start": 2, "end": 100})
Output:

o bar baz_test
Example (Substring_highStart)
eval(`substring("foo", start, end)`, map[string]interface{}{"start": 3, "end": -1})
Output:

Example (Substring_withEnd)
eval(`substring("foo bar baz_test", start, end)`, map[string]interface{}{"start": 2, "end": 4})
Output:

o b
Example (Sum)
eval(`sum(1, 2, "foo", 3.4, 4, "3")`, 10.4)
Output:

13.4
Example (Title)
eval(`title("foo bAR")`, nil)
Output:

Foo bAR
Example (ToJSON)
var (
	p = map[string]interface{}{
		"vars": Must(NewVars(
			&Vars{value: map[string]TypedValue{
				"k1": &String{value: "v1"},
				"k2": &String{value: "v2"},
			}},
		)),
	}
)

eval(`toJSON(vars)`, p)
Output:

{"k1":{"@value":"v1","@type":"String"},"k2":{"@value":"v2","@type":"String"}}
Example (ToLower)
eval(`toLower("FOO")`, nil)
Output:

foo
Example (ToUpper)
eval(`toUpper("foo")`, nil)
Output:

FOO
Example (Trim)
eval(`trim(" foo ")`, nil)
Output:

foo
Example (TrimLeft)
eval(`trimLeft(" foo ", " ")`, nil)
Output:

foo
Example (TrimRight)
eval(`trimRight(" foo ", " ")`, nil)
Output:

foo
Example (Unix)
eval(`strftime(ghd, "%L")`, exampleTimeParams)
Output:

728650800
Example (Untitle)
eval(`untitle("Foo Bar")`, nil)
Output:

foo Bar

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFunctions

func AllFunctions() []gval.Language

func ArrayFunctions

func ArrayFunctions() []gval.Language

func Assign

func Assign(base TypedValue, path string, val TypedValue) (err error)

func CastToAny

func CastToAny(val interface{}) (interface{}, error)

func CastToBoolean

func CastToBoolean(val interface{}) (out bool, err error)

func CastToBytes

func CastToBytes(val interface{}) (out []byte, err error)

func CastToDateTime

func CastToDateTime(val interface{}) (out *time.Time, err error)

func CastToDuration

func CastToDuration(val interface{}) (out time.Duration, err error)

func CastToFloat

func CastToFloat(val interface{}) (out float64, err error)

func CastToHandle

func CastToHandle(val interface{}) (string, error)

func CastToHttpRequest

func CastToHttpRequest(val interface{}) (out *h.Request, err error)

func CastToID

func CastToID(val interface{}) (out uint64, err error)

func CastToInteger

func CastToInteger(val interface{}) (out int64, err error)

func CastToKV

func CastToKV(val interface{}) (out map[string]string, err error)

func CastToKVV

func CastToKVV(val interface{}) (out map[string][]string, err error)

func CastToMeta

func CastToMeta(val interface{}) (out map[string]any, err error)

func CastToReader

func CastToReader(val interface{}) (out io.Reader, err error)

func CastToString

func CastToString(val interface{}) (out string, err error)

func CastToStringSlice

func CastToStringSlice(val interface{}) (out []string, err error)

func CastToUnsignedInteger

func CastToUnsignedInteger(val interface{}) (out uint64, err error)

func CastToUrl

func CastToUrl(val interface{}) (out *url.URL, err error)

func CastToVars

func CastToVars(val interface{}) (out map[string]TypedValue, err error)

func GenericFunctions

func GenericFunctions() []gval.Language

func Has

func Has(arr interface{}, vv ...interface{}) (b bool, err error)

has finds any occurrence of the values in slice or key in a map

func JsonFunctions

func JsonFunctions() []gval.Language

func KvFunctions

func KvFunctions() []gval.Language

func NewGvalParser

func NewGvalParser() *gvalParser

func NumericFunctions

func NumericFunctions() []gval.Language

func Parser

func Parser() gval.Language

Parser returns global parser instance

func Path

func Path(p string) (out *exprPath)

Path initializes a new exprPath helper to efficiently traverse the path

func PathBase

func PathBase(path string) string

func ResolveTypes

func ResolveTypes(rt resolvableType, resolver func(typ string) Type) error

func StringFunctions

func StringFunctions() []gval.Language

func TimeFunctions

func TimeFunctions() []gval.Language

func UntypedValue

func UntypedValue(val interface{}) interface{}

Types

type Any

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

Any is an expression type, wrapper for interface{} type

func NewAny

func NewAny(val interface{}) (*Any, error)

NewAny creates new instance of Any expression type

func (*Any) Assign

func (t *Any) Assign(val interface{}) error

Assign new value to Any

value is first passed through CastToAny

func (Any) Cast

func (Any) Cast(val interface{}) (TypedValue, error)

Cast converts value to interface{}

func (*Any) Clone

func (v *Any) Clone() (out TypedValue, err error)

func (*Any) Get

func (t *Any) Get() interface{}

Get return underlying value on Any

func (*Any) GetValue

func (t *Any) GetValue() interface{}

GetValue returns underlying value on Any

func (Any) Type

func (Any) Type() string

Type return type name

type Array

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

Array is an expression type, wrapper for []TypedValue type

func NewArray

func NewArray(val interface{}) (*Array, error)

NewArray creates new instance of Array expression type

func (*Array) Assign

func (t *Array) Assign(val interface{}) error

Assign new value to Array

value is first passed through CastToArray

func (Array) Cast

func (Array) Cast(val interface{}) (TypedValue, error)

Cast converts value to []TypedValue

func (*Array) Clone

func (v *Array) Clone() (out TypedValue, err error)

func (*Array) Decode

func (t *Array) Decode(dst reflect.Value) error

func (*Array) Get

func (t *Array) Get() interface{}

Get return underlying value on Array

func (*Array) GetValue

func (t *Array) GetValue() []TypedValue

GetValue returns underlying value on Array

func (Array) Has

func (t Array) Has(k string) bool

Select is field accessor for *types.Record

Similar to SelectGVal but returns typed values

func (*Array) IsEmpty

func (t *Array) IsEmpty() bool

func (Array) MarshalJSON

func (t Array) MarshalJSON() ([]byte, error)

func (*Array) Push

func (t *Array) Push(v TypedValue)

Push appends value to array

func (Array) Select

func (t Array) Select(k string) (TypedValue, error)

Select is field accessor for *types.Array

Similar to SelectGVal but returns typed values

func (Array) SelectGVal

func (t Array) SelectGVal(ctx context.Context, k string) (interface{}, error)

SelectGVal implements gval.Selector requirements

It allows gval lib to access Record's underlying value (*types.Array) and it's fields

func (*Array) Slice

func (t *Array) Slice() []interface{}

func (Array) Type

func (Array) Type() string

Type return type name

type Assigner

type Assigner interface {
	Assign(interface{}) error
}

type Boolean

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

Boolean is an expression type, wrapper for bool type

func NewBoolean

func NewBoolean(val interface{}) (*Boolean, error)

NewBoolean creates new instance of Boolean expression type

func (*Boolean) Assign

func (t *Boolean) Assign(val interface{}) error

Assign new value to Boolean

value is first passed through CastToBoolean

func (Boolean) Cast

func (Boolean) Cast(val interface{}) (TypedValue, error)

Cast converts value to bool

func (*Boolean) Clone

func (v *Boolean) Clone() (out TypedValue, err error)

func (Boolean) Compare

func (t Boolean) Compare(to TypedValue) (int, error)

Compare the two Boolean values

func (*Boolean) Get

func (t *Boolean) Get() interface{}

Get return underlying value on Boolean

func (*Boolean) GetValue

func (t *Boolean) GetValue() bool

GetValue returns underlying value on Boolean

func (Boolean) Type

func (Boolean) Type() string

Type return type name

type Bytes

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

Bytes is an expression type, wrapper for []byte type

func NewBytes

func NewBytes(val interface{}) (*Bytes, error)

NewBytes creates new instance of Bytes expression type

func (*Bytes) Assign

func (t *Bytes) Assign(val interface{}) error

Assign new value to Bytes

value is first passed through CastToBytes

func (Bytes) Cast

func (Bytes) Cast(val interface{}) (TypedValue, error)

Cast converts value to []byte

func (*Bytes) Clone

func (v *Bytes) Clone() (out TypedValue, err error)

func (*Bytes) Get

func (t *Bytes) Get() interface{}

Get return underlying value on Bytes

func (*Bytes) GetValue

func (t *Bytes) GetValue() []byte

GetValue returns underlying value on Bytes

func (*Bytes) IsEmpty

func (t *Bytes) IsEmpty() bool

func (Bytes) Type

func (Bytes) Type() string

Type return type name

type Comparable

type Comparable interface {
	Compare(TypedValue) (int, error)
}

type DateTime

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

DateTime is an expression type, wrapper for *time.Time type

func NewDateTime

func NewDateTime(val interface{}) (*DateTime, error)

NewDateTime creates new instance of DateTime expression type

func (*DateTime) Assign

func (t *DateTime) Assign(val interface{}) error

Assign new value to DateTime

value is first passed through CastToDateTime

func (DateTime) Cast

func (DateTime) Cast(val interface{}) (TypedValue, error)

Cast converts value to *time.Time

func (*DateTime) Clone

func (v *DateTime) Clone() (out TypedValue, err error)

func (DateTime) Compare

func (t DateTime) Compare(to TypedValue) (int, error)

Compare the two DateTime values

func (*DateTime) Get

func (t *DateTime) Get() interface{}

Get return underlying value on DateTime

func (*DateTime) GetValue

func (t *DateTime) GetValue() *time.Time

GetValue returns underlying value on DateTime

func (DateTime) IsEmpty

func (v DateTime) IsEmpty() bool

func (DateTime) Type

func (DateTime) Type() string

Type return type name

type DeepFieldAssigner

type DeepFieldAssigner interface {
	AssignFieldValue(Pather, TypedValue) error
}

type Dict

type Dict interface {
	Dict() map[string]interface{}
}

type Duration

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

Duration is an expression type, wrapper for time.Duration type

func NewDuration

func NewDuration(val interface{}) (*Duration, error)

NewDuration creates new instance of Duration expression type

func (*Duration) Assign

func (t *Duration) Assign(val interface{}) error

Assign new value to Duration

value is first passed through CastToDuration

func (Duration) Cast

func (Duration) Cast(val interface{}) (TypedValue, error)

Cast converts value to time.Duration

func (*Duration) Clone

func (v *Duration) Clone() (out TypedValue, err error)

func (Duration) Compare

func (t Duration) Compare(to TypedValue) (int, error)

Compare the two Duration values

func (*Duration) Get

func (t *Duration) Get() interface{}

Get return underlying value on Duration

func (*Duration) GetValue

func (t *Duration) GetValue() time.Duration

GetValue returns underlying value on Duration

func (Duration) Type

func (Duration) Type() string

Type return type name

type Evaluable

type Evaluable interface {
	Eval(context.Context, *Vars) (interface{}, error)
	Test(context.Context, *Vars) (bool, error)
}

type Evaluator

type Evaluator interface {
	GetExpr() string
	SetEval(eval Evaluable)
}

type FieldAssigner

type FieldAssigner interface {
	AssignFieldValue(string, TypedValue) error
}

type FieldSelector

type FieldSelector interface {
	Has(k string) bool
	Select(k string) (TypedValue, error)
}

type Float

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

Float is an expression type, wrapper for float64 type

func NewFloat

func NewFloat(val interface{}) (*Float, error)

NewFloat creates new instance of Float expression type

func (*Float) Assign

func (t *Float) Assign(val interface{}) error

Assign new value to Float

value is first passed through CastToFloat

func (Float) Cast

func (Float) Cast(val interface{}) (TypedValue, error)

Cast converts value to float64

func (*Float) Clone

func (v *Float) Clone() (out TypedValue, err error)

func (Float) Compare

func (t Float) Compare(to TypedValue) (int, error)

Compare the two Float values

func (*Float) Get

func (t *Float) Get() interface{}

Get return underlying value on Float

func (*Float) GetValue

func (t *Float) GetValue() float64

GetValue returns underlying value on Float

func (Float) Type

func (Float) Type() string

Type return type name

type Handle

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

Handle is an expression type, wrapper for string type

func NewHandle

func NewHandle(val interface{}) (*Handle, error)

NewHandle creates new instance of Handle expression type

func (*Handle) Assign

func (t *Handle) Assign(val interface{}) error

Assign new value to Handle

value is first passed through CastToHandle

func (Handle) Cast

func (Handle) Cast(val interface{}) (TypedValue, error)

Cast converts value to string

func (*Handle) Clone

func (v *Handle) Clone() (out TypedValue, err error)

func (Handle) Compare

func (t Handle) Compare(to TypedValue) (int, error)

Compare the two Handle values

func (*Handle) Get

func (t *Handle) Get() interface{}

Get return underlying value on Handle

func (*Handle) GetValue

func (t *Handle) GetValue() string

GetValue returns underlying value on Handle

func (Handle) Type

func (Handle) Type() string

Type return type name

type HttpRequest

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

HttpRequest is an expression type, wrapper for *http.Request type

func NewHttpRequest

func NewHttpRequest(val interface{}) (*HttpRequest, error)

NewHttpRequest creates new instance of HttpRequest expression type

func (*HttpRequest) Assign

func (t *HttpRequest) Assign(val interface{}) error

Assign new value to HttpRequest

value is first passed through CastToHttpRequest

func (*HttpRequest) AssignFieldValue

func (t *HttpRequest) AssignFieldValue(key string, val TypedValue) error

func (HttpRequest) Cast

func (HttpRequest) Cast(val interface{}) (TypedValue, error)

Cast converts value to *http.Request

func (*HttpRequest) Clone

func (v *HttpRequest) Clone() (out TypedValue, err error)

func (*HttpRequest) Get

func (t *HttpRequest) Get() interface{}

Get return underlying value on HttpRequest

func (*HttpRequest) GetValue

func (t *HttpRequest) GetValue() *http.Request

GetValue returns underlying value on HttpRequest

func (*HttpRequest) Has

func (t *HttpRequest) Has(k string) bool

func (*HttpRequest) Select

func (t *HttpRequest) Select(k string) (TypedValue, error)

Select is field accessor for *http.Request

Similar to SelectGVal but returns typed values

func (*HttpRequest) SelectGVal

func (t *HttpRequest) SelectGVal(ctx context.Context, k string) (interface{}, error)

SelectGVal implements gval.Selector requirements

It allows gval lib to access HttpRequest's underlying value (*http.Request) and it's fields

func (HttpRequest) Type

func (HttpRequest) Type() string

Type return type name

type ID

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

ID is an expression type, wrapper for uint64 type

func NewID

func NewID(val interface{}) (*ID, error)

NewID creates new instance of ID expression type

func (*ID) Assign

func (t *ID) Assign(val interface{}) error

Assign new value to ID

value is first passed through CastToID

func (ID) Cast

func (ID) Cast(val interface{}) (TypedValue, error)

Cast converts value to uint64

func (*ID) Clone

func (v *ID) Clone() (out TypedValue, err error)

func (ID) Compare

func (t ID) Compare(to TypedValue) (int, error)

Compare the two ID values

func (*ID) Get

func (t *ID) Get() interface{}

Get return underlying value on ID

func (*ID) GetValue

func (t *ID) GetValue() uint64

GetValue returns underlying value on ID

func (ID) MarshalJSON

func (t ID) MarshalJSON() ([]byte, error)

func (ID) Type

func (ID) Type() string

Type return type name

type Integer

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

Integer is an expression type, wrapper for int64 type

func NewInteger

func NewInteger(val interface{}) (*Integer, error)

NewInteger creates new instance of Integer expression type

func (*Integer) Assign

func (t *Integer) Assign(val interface{}) error

Assign new value to Integer

value is first passed through CastToInteger

func (Integer) Cast

func (Integer) Cast(val interface{}) (TypedValue, error)

Cast converts value to int64

func (*Integer) Clone

func (v *Integer) Clone() (out TypedValue, err error)

func (Integer) Compare

func (t Integer) Compare(to TypedValue) (int, error)

Compare the two Integer values

func (*Integer) Get

func (t *Integer) Get() interface{}

Get return underlying value on Integer

func (*Integer) GetValue

func (t *Integer) GetValue() int64

GetValue returns underlying value on Integer

func (Integer) Type

func (Integer) Type() string

Type return type name

type Iterator

type Iterator interface {
	Each(func(k string, v TypedValue) error) error
}

type KV

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

KV is an expression type, wrapper for map[string]string type

func EmptyKV

func EmptyKV() *KV

func NewKV

func NewKV(val interface{}) (*KV, error)

NewKV creates new instance of KV expression type

func (*KV) Assign

func (t *KV) Assign(val interface{}) error

Assign new value to KV

value is first passed through CastToKV

func (*KV) AssignFieldValue

func (t *KV) AssignFieldValue(key string, val TypedValue) error

func (KV) Cast

func (KV) Cast(val interface{}) (TypedValue, error)

Cast converts value to map[string]string

func (*KV) Clone

func (v *KV) Clone() (out TypedValue, err error)

func (*KV) Delete

func (t *KV) Delete(keys ...string) (out TypedValue, err error)

Delete take keys returns KV without those key value pair

func (*KV) Each

func (t *KV) Each(fn func(k string, v TypedValue) error) (err error)

func (*KV) Filter

func (t *KV) Filter(keys ...string) (out TypedValue, err error)

Filter take keys returns KV with only those key value pair

func (*KV) Get

func (t *KV) Get() interface{}

Get return underlying value on KV

func (*KV) GetValue

func (t *KV) GetValue() map[string]string

GetValue returns underlying value on KV

func (*KV) Has

func (t *KV) Has(k string) bool

func (*KV) Merge

func (t *KV) Merge(nn ...Iterator) (out TypedValue, err error)

Merge combines the given KVs into KV NOTE: It will return CLONE of the original KV, if its called without any parameters

func (*KV) Select

func (t *KV) Select(k string) (TypedValue, error)

func (*KV) SelectGVal

func (t *KV) SelectGVal(_ context.Context, k string) (interface{}, error)

func (KV) Type

func (KV) Type() string

Type return type name

type KVV

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

KVV is an expression type, wrapper for map[string][]string type

func EmptyKVV

func EmptyKVV() *KVV

func NewKVV

func NewKVV(val interface{}) (*KVV, error)

NewKVV creates new instance of KVV expression type

func (*KVV) Assign

func (t *KVV) Assign(val interface{}) error

Assign new value to KVV

value is first passed through CastToKVV

func (*KVV) AssignFieldValue

func (t *KVV) AssignFieldValue(p Pather, val TypedValue) error

func (KVV) Cast

func (KVV) Cast(val interface{}) (TypedValue, error)

Cast converts value to map[string][]string

func (*KVV) Clone

func (v *KVV) Clone() (out TypedValue, err error)

func (*KVV) Delete

func (t *KVV) Delete(keys ...string) (out TypedValue, err error)

Delete take keys returns KVV without those key value pair

func (*KVV) Each

func (t *KVV) Each(fn func(k string, v TypedValue) error) (err error)

func (*KVV) Filter

func (t *KVV) Filter(keys ...string) (out TypedValue, err error)

Filter take keys returns KVV with only those key value pair

func (*KVV) Get

func (t *KVV) Get() interface{}

Get return underlying value on KVV

func (*KVV) GetValue

func (t *KVV) GetValue() map[string][]string

GetValue returns underlying value on KVV

func (*KVV) Merge

func (t *KVV) Merge(nn ...Iterator) (out TypedValue, err error)

Merge combines the given KVVs into KVV NOTE: It will return CLONE of the original KVV, if its called without any parameters

func (*KVV) Select

func (t *KVV) Select(k string) (TypedValue, error)

func (*KVV) SelectGVal

func (t *KVV) SelectGVal(_ context.Context, k string) (interface{}, error)

func (KVV) Type

func (KVV) Type() string

Type return type name

type Meta

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

Meta is an expression type, wrapper for map[string]any type

func NewMeta

func NewMeta(val interface{}) (*Meta, error)

NewMeta creates new instance of Meta expression type

func (*Meta) Assign

func (t *Meta) Assign(val interface{}) error

Assign new value to Meta

value is first passed through CastToMeta

func (Meta) Cast

func (Meta) Cast(val interface{}) (TypedValue, error)

Cast converts value to map[string]any

func (*Meta) Clone

func (v *Meta) Clone() (out TypedValue, err error)

func (*Meta) Get

func (t *Meta) Get() interface{}

Get return underlying value on Meta

func (*Meta) GetValue

func (t *Meta) GetValue() map[string]any

GetValue returns underlying value on Meta

func (Meta) Type

func (Meta) Type() string

Type return type name

type Parsable

type Parsable interface {
	Parse(string) (Evaluable, error)
	ParseEvaluators(ee ...Evaluator) error
}

func NewParser

func NewParser() Parsable

type Pather

type Pather interface {
	String() string
	More() bool
	IsLast() bool
	Get() string
	Rest() string
	Next() (err error)
}

type Reader

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

Reader is an expression type, wrapper for io.Reader type

func NewReader

func NewReader(val interface{}) (*Reader, error)

NewReader creates new instance of Reader expression type

func (*Reader) Assign

func (t *Reader) Assign(val interface{}) error

Assign new value to Reader

value is first passed through CastToReader

func (Reader) Cast

func (Reader) Cast(val interface{}) (TypedValue, error)

Cast converts value to io.Reader

func (*Reader) Clone

func (v *Reader) Clone() (out TypedValue, err error)

func (*Reader) Get

func (t *Reader) Get() interface{}

Get return underlying value on Reader

func (*Reader) GetValue

func (t *Reader) GetValue() io.Reader

GetValue returns underlying value on Reader

func (Reader) Type

func (Reader) Type() string

Type return type name

type Slice

type Slice interface {
	Slice() []interface{}
}

type String

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

String is an expression type, wrapper for string type

func NewString

func NewString(val interface{}) (*String, error)

NewString creates new instance of String expression type

func (*String) Assign

func (t *String) Assign(val interface{}) error

Assign new value to String

value is first passed through CastToString

func (String) Cast

func (String) Cast(val interface{}) (TypedValue, error)

Cast converts value to string

func (*String) Clone

func (v *String) Clone() (out TypedValue, err error)

func (String) Compare

func (t String) Compare(to TypedValue) (int, error)

Compare the two String values

func (*String) Get

func (t *String) Get() interface{}

Get return underlying value on String

func (*String) GetValue

func (t *String) GetValue() string

GetValue returns underlying value on String

func (String) Type

func (String) Type() string

Type return type name

type Type

type Type interface {
	Type() string
	Cast(interface{}) (TypedValue, error)
}

type TypeValueDecoder

type TypeValueDecoder interface {
	Decode(dst reflect.Value) error
}

type TypedValue

type TypedValue interface {
	Type
	Assigner
	Clone() (TypedValue, error)
	Get() interface{}
}

func CastToArray

func CastToArray(val interface{}) (out []TypedValue, err error)

func Must

func Must(v TypedValue, err error) TypedValue

func NewUnresolved

func NewUnresolved(typ string, val interface{}) (TypedValue, error)

NewUnresolved creates new instance of Unresolved expression type

func Select

func Select(base TypedValue, path string) (out TypedValue, err error)

func Typify

func Typify(in interface{}) (tv TypedValue, err error)

Typify detects input type and wraps it with expression type

type Unresolved

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

Unresolved is a special type that holds value + type it needs to be resolved to

This solves problem with typed value serialization

func (*Unresolved) Assign

func (t *Unresolved) Assign(interface{}) (err error)

func (Unresolved) Cast

func (Unresolved) Cast(interface{}) (TypedValue, error)

Casts value to interface{}

func (Unresolved) Clone

func (v Unresolved) Clone() (out TypedValue, err error)

func (Unresolved) Get

func (t Unresolved) Get() interface{}

Returns underlying value on Unresolved

func (Unresolved) Type

func (t Unresolved) Type() string

Returns type name

type UnsignedInteger

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

UnsignedInteger is an expression type, wrapper for uint64 type

func NewUnsignedInteger

func NewUnsignedInteger(val interface{}) (*UnsignedInteger, error)

NewUnsignedInteger creates new instance of UnsignedInteger expression type

func (*UnsignedInteger) Assign

func (t *UnsignedInteger) Assign(val interface{}) error

Assign new value to UnsignedInteger

value is first passed through CastToUnsignedInteger

func (UnsignedInteger) Cast

func (UnsignedInteger) Cast(val interface{}) (TypedValue, error)

Cast converts value to uint64

func (*UnsignedInteger) Clone

func (v *UnsignedInteger) Clone() (out TypedValue, err error)

func (UnsignedInteger) Compare

func (t UnsignedInteger) Compare(to TypedValue) (int, error)

Compare the two UnsignedInteger values

func (*UnsignedInteger) Get

func (t *UnsignedInteger) Get() interface{}

Get return underlying value on UnsignedInteger

func (*UnsignedInteger) GetValue

func (t *UnsignedInteger) GetValue() uint64

GetValue returns underlying value on UnsignedInteger

func (UnsignedInteger) Type

func (UnsignedInteger) Type() string

Type return type name

type Url

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

Url is an expression type, wrapper for *url.URL type

func NewUrl

func NewUrl(val interface{}) (*Url, error)

NewUrl creates new instance of Url expression type

func (*Url) Assign

func (t *Url) Assign(val interface{}) error

Assign new value to Url

value is first passed through CastToUrl

func (Url) Cast

func (Url) Cast(val interface{}) (TypedValue, error)

Cast converts value to *url.URL

func (*Url) Clone

func (v *Url) Clone() (out TypedValue, err error)

func (*Url) Get

func (t *Url) Get() interface{}

Get return underlying value on Url

func (*Url) GetValue

func (t *Url) GetValue() *url.URL

GetValue returns underlying value on Url

func (Url) Type

func (Url) Type() string

Type return type name

type Vars

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

Vars is an expression type, wrapper for map[string]TypedValue type

func EmptyVars

func EmptyVars() *Vars

func NewVars

func NewVars(val interface{}) (*Vars, error)

NewVars creates new instance of Vars expression type

func (*Vars) Assign

func (t *Vars) Assign(val interface{}) error

Assign new value to Vars

value is first passed through CastToVars

func (*Vars) AssignFieldValue

func (t *Vars) AssignFieldValue(key string, val TypedValue) (err error)

func (Vars) Cast

func (Vars) Cast(val interface{}) (TypedValue, error)

Cast converts value to map[string]TypedValue

func (*Vars) Clone

func (v *Vars) Clone() (out TypedValue, err error)

func (*Vars) Copy

func (t *Vars) Copy(dst *Vars, kk ...string)

Copy takes base variables and copies all to dst

func (*Vars) Decode

func (t *Vars) Decode(dst interface{}) (err error)

func (*Vars) Delete

func (t *Vars) Delete(keys ...string) (out TypedValue, err error)

Delete take keys returns Vars without those key value pair

func (*Vars) Dict

func (t *Vars) Dict() (out map[string]interface{})

func (*Vars) Each

func (t *Vars) Each(fn func(k string, v TypedValue) error) (err error)

func (*Vars) Filter

func (t *Vars) Filter(keys ...string) (out TypedValue, err error)

Filter take keys returns Vars with only those key value pair

func (*Vars) Get

func (t *Vars) Get() interface{}

Get return underlying value on Vars

func (*Vars) GetValue

func (t *Vars) GetValue() map[string]TypedValue

GetValue returns underlying value on Vars

func (*Vars) Has

func (t *Vars) Has(key string) bool

Has returns true key is present

func (*Vars) HasAll

func (t *Vars) HasAll(key string, kk ...string) bool

HasAll returns true if all keys are present

func (*Vars) HasAny

func (t *Vars) HasAny(key string, kk ...string) bool

HasAny returns true if all keys are present

func (*Vars) IsEmpty

func (t *Vars) IsEmpty() bool

func (*Vars) Len

func (t *Vars) Len() (out int)

func (*Vars) MarshalJSON

func (t *Vars) MarshalJSON() (out []byte, err error)

MarshalJSON returns JSON encoding of expression

func (*Vars) Merge

func (t *Vars) Merge(nn ...Iterator) (out TypedValue, err error)

Merge combines the given Vars(es) into Vars NOTE: It will return CLONE of the original Vars, if it's called without any parameters

func (*Vars) MustMerge

func (t *Vars) MustMerge(nn ...Iterator) *Vars

MustMerge returns Vars after merging the given Vars(es) into it

func (*Vars) ResolveTypes

func (t *Vars) ResolveTypes(res func(typ string) Type) (err error)

func (*Vars) Scan

func (t *Vars) Scan(src any) error

func (*Vars) Select

func (t *Vars) Select(k string) (out TypedValue, err error)

func (*Vars) SelectGVal

func (t *Vars) SelectGVal(_ context.Context, k string) (out interface{}, err error)

func (*Vars) Set

func (t *Vars) Set(k string, v interface{}) (err error)

Set or update the specific key value in Vars

func (Vars) Type

func (Vars) Type() string

Type return type name

func (*Vars) UnmarshalJSON

func (t *Vars) UnmarshalJSON(in []byte) (err error)

UnmarshalJSON unmarshal JSON value into Vars

func (*Vars) Value

func (t *Vars) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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