Tweak expr record value selection and bool casting

* properly handle casting of false values (empty string)
* add support for record.values.xyz expressions where values is not set
This commit is contained in:
Tomaž Jerman
2021-10-01 12:40:23 +02:00
parent 2ee926940a
commit 2def92d41f
4 changed files with 22 additions and 9 deletions
+10
View File
@@ -7,6 +7,12 @@ import (
"github.com/PaesslerAG/gval"
)
type (
empty interface {
IsEmpty() bool
}
)
func GenericFunctions() []gval.Language {
return []gval.Language{
gval.Function("coalesce", coalesce),
@@ -57,6 +63,10 @@ func isEmpty(i interface{}) bool {
return true
}
if c, ok := i.(empty); ok {
return c.IsEmpty()
}
switch reflect.TypeOf(i).Kind() {
case reflect.Slice, reflect.Array, reflect.Map:
return reflect.ValueOf(i).Len() == 0