add a LogInfo expr helper (#2179)

This commit is contained in:
Thibault "bui" Koechlin 2023-05-03 10:07:11 +02:00 committed by GitHub
parent 6bb20fa951
commit 4ff8f498ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -377,6 +377,13 @@ var exprFuncs = []exprCustomFunc{
new(func(string, string) bool), new(func(string, string) bool),
}, },
}, },
{
name: "LogInfo",
function: LogInfo,
signature: []interface{}{
new(func(string, ...interface{}) bool),
},
},
} }
//go 1.20 "CutPrefix": strings.CutPrefix, //go 1.20 "CutPrefix": strings.CutPrefix,

View file

@ -1,6 +1,10 @@
package exprhelpers package exprhelpers
import "strings" import (
"strings"
log "github.com/sirupsen/logrus"
)
//Wrappers for stdlib strings function exposed in expr //Wrappers for stdlib strings function exposed in expr
@ -67,3 +71,8 @@ func TrimSpace(params ...any) (any, error) {
func TrimSuffix(params ...any) (any, error) { func TrimSuffix(params ...any) (any, error) {
return strings.TrimSuffix(params[0].(string), params[1].(string)), nil return strings.TrimSuffix(params[0].(string), params[1].(string)), nil
} }
func LogInfo(params ...any) (any, error) {
log.Infof(params[0].(string), params[1:]...)
return true, nil
}