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 ¶
- func AllFunctions() []gval.Language
- func ArrayFunctions() []gval.Language
- func Assign(base TypedValue, path string, val TypedValue) (err error)
- func CastToAny(val interface{}) (interface{}, error)
- func CastToBoolean(val interface{}) (out bool, err error)
- func CastToBytes(val interface{}) (out []byte, err error)
- func CastToDateTime(val interface{}) (out *time.Time, err error)
- func CastToDuration(val interface{}) (out time.Duration, err error)
- func CastToFloat(val interface{}) (out float64, err error)
- func CastToHandle(val interface{}) (string, error)
- func CastToHttpRequest(val interface{}) (out *h.Request, err error)
- func CastToID(val interface{}) (out uint64, err error)
- func CastToInteger(val interface{}) (out int64, err error)
- func CastToKV(val interface{}) (out map[string]string, err error)
- func CastToKVV(val interface{}) (out map[string][]string, err error)
- func CastToMeta(val interface{}) (out map[string]any, err error)
- func CastToReader(val interface{}) (out io.Reader, err error)
- func CastToString(val interface{}) (out string, err error)
- func CastToStringSlice(val interface{}) (out []string, err error)
- func CastToUnsignedInteger(val interface{}) (out uint64, err error)
- func CastToUrl(val interface{}) (out *url.URL, err error)
- func CastToVars(val interface{}) (out map[string]TypedValue, err error)
- func GenericFunctions() []gval.Language
- func Has(arr interface{}, vv ...interface{}) (b bool, err error)
- func JsonFunctions() []gval.Language
- func KvFunctions() []gval.Language
- func NewGvalParser() *gvalParser
- func NumericFunctions() []gval.Language
- func Parser() gval.Language
- func Path(p string) (out *exprPath)
- func PathBase(path string) string
- func ResolveTypes(rt resolvableType, resolver func(typ string) Type) error
- func StringFunctions() []gval.Language
- func TimeFunctions() []gval.Language
- func UntypedValue(val interface{}) interface{}
- type Any
- type Array
- func (t *Array) Assign(val interface{}) error
- func (Array) Cast(val interface{}) (TypedValue, error)
- func (v *Array) Clone() (out TypedValue, err error)
- func (t *Array) Decode(dst reflect.Value) error
- func (t *Array) Get() interface{}
- func (t *Array) GetValue() []TypedValue
- func (t Array) Has(k string) bool
- func (t *Array) IsEmpty() bool
- func (t Array) MarshalJSON() ([]byte, error)
- func (t *Array) Push(v TypedValue)
- func (t Array) Select(k string) (TypedValue, error)
- func (t Array) SelectGVal(ctx context.Context, k string) (interface{}, error)
- func (t *Array) Slice() []interface{}
- func (Array) Type() string
- type Assigner
- type Boolean
- func (t *Boolean) Assign(val interface{}) error
- func (Boolean) Cast(val interface{}) (TypedValue, error)
- func (v *Boolean) Clone() (out TypedValue, err error)
- func (t Boolean) Compare(to TypedValue) (int, error)
- func (t *Boolean) Get() interface{}
- func (t *Boolean) GetValue() bool
- func (Boolean) Type() string
- type Bytes
- type Comparable
- type DateTime
- func (t *DateTime) Assign(val interface{}) error
- func (DateTime) Cast(val interface{}) (TypedValue, error)
- func (v *DateTime) Clone() (out TypedValue, err error)
- func (t DateTime) Compare(to TypedValue) (int, error)
- func (t *DateTime) Get() interface{}
- func (t *DateTime) GetValue() *time.Time
- func (v DateTime) IsEmpty() bool
- func (DateTime) Type() string
- type DeepFieldAssigner
- type Dict
- type Duration
- func (t *Duration) Assign(val interface{}) error
- func (Duration) Cast(val interface{}) (TypedValue, error)
- func (v *Duration) Clone() (out TypedValue, err error)
- func (t Duration) Compare(to TypedValue) (int, error)
- func (t *Duration) Get() interface{}
- func (t *Duration) GetValue() time.Duration
- func (Duration) Type() string
- type Evaluable
- type Evaluator
- type FieldAssigner
- type FieldSelector
- type Float
- type Handle
- func (t *Handle) Assign(val interface{}) error
- func (Handle) Cast(val interface{}) (TypedValue, error)
- func (v *Handle) Clone() (out TypedValue, err error)
- func (t Handle) Compare(to TypedValue) (int, error)
- func (t *Handle) Get() interface{}
- func (t *Handle) GetValue() string
- func (Handle) Type() string
- type HttpRequest
- func (t *HttpRequest) Assign(val interface{}) error
- func (t *HttpRequest) AssignFieldValue(key string, val TypedValue) error
- func (HttpRequest) Cast(val interface{}) (TypedValue, error)
- func (v *HttpRequest) Clone() (out TypedValue, err error)
- func (t *HttpRequest) Get() interface{}
- func (t *HttpRequest) GetValue() *http.Request
- func (t *HttpRequest) Has(k string) bool
- func (t *HttpRequest) Select(k string) (TypedValue, error)
- func (t *HttpRequest) SelectGVal(ctx context.Context, k string) (interface{}, error)
- func (HttpRequest) Type() string
- type ID
- func (t *ID) Assign(val interface{}) error
- func (ID) Cast(val interface{}) (TypedValue, error)
- func (v *ID) Clone() (out TypedValue, err error)
- func (t ID) Compare(to TypedValue) (int, error)
- func (t *ID) Get() interface{}
- func (t *ID) GetValue() uint64
- func (t ID) MarshalJSON() ([]byte, error)
- func (ID) Type() string
- type Integer
- func (t *Integer) Assign(val interface{}) error
- func (Integer) Cast(val interface{}) (TypedValue, error)
- func (v *Integer) Clone() (out TypedValue, err error)
- func (t Integer) Compare(to TypedValue) (int, error)
- func (t *Integer) Get() interface{}
- func (t *Integer) GetValue() int64
- func (Integer) Type() string
- type Iterator
- type KV
- func (t *KV) Assign(val interface{}) error
- func (t *KV) AssignFieldValue(key string, val TypedValue) error
- func (KV) Cast(val interface{}) (TypedValue, error)
- func (v *KV) Clone() (out TypedValue, err error)
- func (t *KV) Delete(keys ...string) (out TypedValue, err error)
- func (t *KV) Each(fn func(k string, v TypedValue) error) (err error)
- func (t *KV) Filter(keys ...string) (out TypedValue, err error)
- func (t *KV) Get() interface{}
- func (t *KV) GetValue() map[string]string
- func (t *KV) Has(k string) bool
- func (t *KV) Merge(nn ...Iterator) (out TypedValue, err error)
- func (t *KV) Select(k string) (TypedValue, error)
- func (t *KV) SelectGVal(_ context.Context, k string) (interface{}, error)
- func (KV) Type() string
- type KVV
- func (t *KVV) Assign(val interface{}) error
- func (t *KVV) AssignFieldValue(p Pather, val TypedValue) error
- func (KVV) Cast(val interface{}) (TypedValue, error)
- func (v *KVV) Clone() (out TypedValue, err error)
- func (t *KVV) Delete(keys ...string) (out TypedValue, err error)
- func (t *KVV) Each(fn func(k string, v TypedValue) error) (err error)
- func (t *KVV) Filter(keys ...string) (out TypedValue, err error)
- func (t *KVV) Get() interface{}
- func (t *KVV) GetValue() map[string][]string
- func (t *KVV) Merge(nn ...Iterator) (out TypedValue, err error)
- func (t *KVV) Select(k string) (TypedValue, error)
- func (t *KVV) SelectGVal(_ context.Context, k string) (interface{}, error)
- func (KVV) Type() string
- type Meta
- type Parsable
- type Pather
- type Reader
- type Slice
- type String
- func (t *String) Assign(val interface{}) error
- func (String) Cast(val interface{}) (TypedValue, error)
- func (v *String) Clone() (out TypedValue, err error)
- func (t String) Compare(to TypedValue) (int, error)
- func (t *String) Get() interface{}
- func (t *String) GetValue() string
- func (String) Type() string
- type Type
- type TypeValueDecoder
- type TypedValue
- func CastToArray(val interface{}) (out []TypedValue, err error)
- func Must(v TypedValue, err error) TypedValue
- func NewUnresolved(typ string, val interface{}) (TypedValue, error)
- func Select(base TypedValue, path string) (out TypedValue, err error)
- func Typify(in interface{}) (tv TypedValue, err error)
- type Unresolved
- type UnsignedInteger
- func (t *UnsignedInteger) Assign(val interface{}) error
- func (UnsignedInteger) Cast(val interface{}) (TypedValue, error)
- func (v *UnsignedInteger) Clone() (out TypedValue, err error)
- func (t UnsignedInteger) Compare(to TypedValue) (int, error)
- func (t *UnsignedInteger) Get() interface{}
- func (t *UnsignedInteger) GetValue() uint64
- func (UnsignedInteger) Type() string
- type Url
- type Vars
- func (t *Vars) Assign(val interface{}) error
- func (t *Vars) AssignFieldValue(key string, val TypedValue) (err error)
- func (Vars) Cast(val interface{}) (TypedValue, error)
- func (v *Vars) Clone() (out TypedValue, err error)
- func (t *Vars) Copy(dst *Vars, kk ...string)
- func (t *Vars) Decode(dst interface{}) (err error)
- func (t *Vars) Delete(keys ...string) (out TypedValue, err error)
- func (t *Vars) Dict() (out map[string]interface{})
- func (t *Vars) Each(fn func(k string, v TypedValue) error) (err error)
- func (t *Vars) Filter(keys ...string) (out TypedValue, err error)
- func (t *Vars) Get() interface{}
- func (t *Vars) GetValue() map[string]TypedValue
- func (t *Vars) Has(key string) bool
- func (t *Vars) HasAll(key string, kk ...string) bool
- func (t *Vars) HasAny(key string, kk ...string) bool
- func (t *Vars) IsEmpty() bool
- func (t *Vars) Len() (out int)
- func (t *Vars) MarshalJSON() (out []byte, err error)
- func (t *Vars) Merge(nn ...Iterator) (out TypedValue, err error)
- func (t *Vars) MustMerge(nn ...Iterator) *Vars
- func (t *Vars) ResolveTypes(res func(typ string) Type) (err error)
- func (t *Vars) Scan(src any) error
- func (t *Vars) Select(k string) (out TypedValue, err error)
- func (t *Vars) SelectGVal(_ context.Context, k string) (out interface{}, err error)
- func (t *Vars) Set(k string, v interface{}) (err error)
- func (Vars) Type() string
- func (t *Vars) UnmarshalJSON(in []byte) (err error)
- func (t *Vars) Value() (driver.Value, error)
Examples ¶
- Package (Abs)
- Package (Average)
- Package (Base64encode)
- Package (Camelize)
- Package (CastFloatToInt)
- Package (CastStringNumberToInt)
- Package (CastStringToInt)
- Package (Ceil)
- Package (Earliest)
- Package (Filter_kv)
- Package (Filter_kvv)
- Package (Filter_vars)
- Package (Floor)
- Package (HasPrefix)
- Package (HasSubstring_caseI)
- Package (HasSubstring_caseS)
- Package (HasSuffix)
- Package (IsEmail)
- Package (IsLeapYear)
- Package (IsUrl)
- Package (IsWeekDay)
- Package (Join)
- Package (Kv_toJSON)
- Package (Latest)
- Package (Ln)
- Package (Log)
- Package (Longest)
- Package (Match)
- Package (Max)
- Package (Merge_kv)
- Package (Merge_kvv)
- Package (Merge_vars)
- Package (Min)
- Package (ModDate)
- Package (ModMonth)
- Package (ModTime)
- Package (ModWeek)
- Package (ModYear)
- Package (Omit_kv)
- Package (Omit_kvv)
- Package (Omit_vars)
- Package (ParseDate)
- Package (ParseDuration)
- Package (ParseISODate)
- Package (Pop_float)
- Package (Pop_int)
- Package (Pop_string)
- Package (Push_bool)
- Package (Push_float)
- Package (Push_int)
- Package (Push_string)
- Package (RandomWithSingleInput)
- Package (RandomWithTwoInput)
- Package (Repeat)
- Package (Replace_all)
- Package (Replace_first)
- Package (Round)
- Package (Set_kv)
- Package (Set_kvv)
- Package (Set_vars)
- Package (Shorten_char)
- Package (Shorten_word)
- Package (Shortest)
- Package (SimpleExpression)
- Package (Snakify)
- Package (Sort_string_asc)
- Package (Sort_string_desc)
- Package (Split)
- Package (Sqrt)
- Package (Strftime)
- Package (StrftimeWithModTime)
- Package (StrftimeWithStringValue)
- Package (Sub)
- Package (SubErrorCheck)
- Package (Substring)
- Package (Substring_endOverflow)
- Package (Substring_highStart)
- Package (Substring_withEnd)
- Package (Sum)
- Package (Title)
- Package (ToJSON)
- Package (ToLower)
- Package (ToUpper)
- Package (Trim)
- Package (TrimLeft)
- Package (TrimRight)
- Package (Unix)
- Package (Untitle)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllFunctions ¶
func ArrayFunctions ¶
func Assign ¶
func Assign(base TypedValue, path string, val TypedValue) (err error)
func CastToBoolean ¶
func CastToBytes ¶
func CastToDateTime ¶
func CastToDuration ¶
func CastToFloat ¶
func CastToHandle ¶
func CastToHttpRequest ¶
func CastToInteger ¶
func CastToMeta ¶
func CastToReader ¶
func CastToString ¶
func CastToStringSlice ¶
func CastToUnsignedInteger ¶
func CastToVars ¶
func CastToVars(val interface{}) (out map[string]TypedValue, err error)
func GenericFunctions ¶
func JsonFunctions ¶
func KvFunctions ¶
func NewGvalParser ¶
func NewGvalParser() *gvalParser
func NumericFunctions ¶
func Path ¶
func Path(p string) (out *exprPath)
Path initializes a new exprPath helper to efficiently traverse the path
func ResolveTypes ¶
func StringFunctions ¶
func TimeFunctions ¶
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 (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)
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array is an expression type, wrapper for []TypedValue type
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) GetValue ¶
func (t *Array) GetValue() []TypedValue
GetValue returns underlying value on Array
func (Array) Has ¶
Select is field accessor for *types.Record
Similar to SelectGVal but returns typed values
func (Array) MarshalJSON ¶
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 ¶
SelectGVal implements gval.Selector requirements
It allows gval lib to access Record's underlying value (*types.Array) and it's fields
type Boolean ¶
type Boolean struct {
// contains filtered or unexported fields
}
Boolean is an expression type, wrapper for bool type
func NewBoolean ¶
NewBoolean creates new instance of Boolean expression type
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
type Bytes ¶
type Bytes struct {
// contains filtered or unexported fields
}
Bytes is an expression type, wrapper for []byte type
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)
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 ¶
NewDateTime creates new instance of DateTime expression type
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
type DeepFieldAssigner ¶
type DeepFieldAssigner interface {
AssignFieldValue(Pather, TypedValue) error
}
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is an expression type, wrapper for time.Duration type
func NewDuration ¶
NewDuration creates new instance of Duration expression type
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
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 (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
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle is an expression type, wrapper for string type
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
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
type ID ¶
type ID struct {
// contains filtered or unexported fields
}
ID is an expression type, wrapper for uint64 type
func (*ID) Clone ¶
func (v *ID) Clone() (out TypedValue, err error)
func (ID) MarshalJSON ¶
type Integer ¶
type Integer struct {
// contains filtered or unexported fields
}
Integer is an expression type, wrapper for int64 type
func NewInteger ¶
NewInteger creates new instance of Integer expression type
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
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV is an expression type, wrapper for map[string]string type
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) Filter ¶
func (t *KV) Filter(keys ...string) (out TypedValue, err error)
Filter take keys returns KV with only those key value pair
type KVV ¶
type KVV struct {
// contains filtered or unexported fields
}
KVV is an expression type, wrapper for map[string][]string type
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) Filter ¶
func (t *KVV) Filter(keys ...string) (out TypedValue, err error)
Filter take keys returns KVV with only those key value pair
type Meta ¶
type Meta struct {
// contains filtered or unexported fields
}
Meta is an expression type, wrapper for map[string]any type
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)
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is an expression type, wrapper for io.Reader type
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)
type String ¶
type String struct {
// contains filtered or unexported fields
}
String is an expression type, wrapper for string type
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
type Type ¶
type Type interface { Type() string Cast(interface{}) (TypedValue, error) }
type TypeValueDecoder ¶
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
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
type Url ¶
type Url struct {
// contains filtered or unexported fields
}
Url is an expression type, wrapper for *url.URL type
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)
type Vars ¶
type Vars struct {
// contains filtered or unexported fields
}
Vars is an expression type, wrapper for map[string]TypedValue type
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) Delete ¶
func (t *Vars) Delete(keys ...string) (out TypedValue, err error)
Delete take keys returns Vars without those key value pair
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) GetValue ¶
func (t *Vars) GetValue() map[string]TypedValue
GetValue returns underlying value on Vars
func (*Vars) MarshalJSON ¶
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) SelectGVal ¶
func (*Vars) UnmarshalJSON ¶
UnmarshalJSON unmarshal JSON value into Vars