[add] Empty expression helper
This commit is contained in:
parent
c5cf0babf9
commit
f6ae0cef47
1 changed files with 26 additions and 0 deletions
|
|
@ -49,6 +49,7 @@ var options = []expr.Option{
|
|||
expr.Function("P_", _process),
|
||||
expr.Function("True", _true),
|
||||
expr.Function("False", _false),
|
||||
expr.Function("Empty", _empty),
|
||||
expr.AllowUndefinedVariables(),
|
||||
}
|
||||
|
||||
|
|
@ -273,6 +274,31 @@ func _true(args ...any) (interface{}, error) {
|
|||
return false, nil
|
||||
}
|
||||
|
||||
func _empty(args ...any) (interface{}, error) {
|
||||
|
||||
if len(args) < 1 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if args[0] == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if v, ok := args[0].(string); ok {
|
||||
return v == "", nil
|
||||
}
|
||||
|
||||
if v, ok := args[0].(int); ok {
|
||||
return v == 0, nil
|
||||
}
|
||||
|
||||
if v, ok := args[0].(bool); ok {
|
||||
return !v, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func _process(args ...any) (interface{}, error) {
|
||||
|
||||
if len(args) < 1 {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue