2020-05-15 09:39:16 +00:00
|
|
|
package exprhelpers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2020-05-22 11:55:48 +00:00
|
|
|
"strings"
|
2020-05-15 09:39:16 +00:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Atof(x string) float64 {
|
|
|
|
log.Debugf("debug atof %s", x)
|
|
|
|
ret, err := strconv.ParseFloat(x, 64)
|
|
|
|
if err != nil {
|
|
|
|
log.Warningf("Atof : can't convert float '%s' : %v", x, err)
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
2020-05-22 11:55:48 +00:00
|
|
|
func StartsWith(s string, pref string) bool {
|
|
|
|
return strings.HasPrefix(s, pref)
|
|
|
|
}
|
|
|
|
|
|
|
|
func EndsWith(s string, suff string) bool {
|
|
|
|
return strings.HasSuffix(s, suff)
|
|
|
|
}
|
|
|
|
|
2020-05-15 09:39:16 +00:00
|
|
|
func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
|
|
|
|
|
2020-05-22 16:12:33 +00:00
|
|
|
var ExprLib = map[string]interface{}{"Atof": Atof, "JsonExtract": JsonExtract, "JsonExtractLib": JsonExtractLib}
|
2020-05-15 09:39:16 +00:00
|
|
|
for k, v := range ctx {
|
|
|
|
ExprLib[k] = v
|
|
|
|
}
|
|
|
|
return ExprLib
|
|
|
|
}
|