exprlib.go 525 B

12345678910111213141516171819202122232425
  1. package exprhelpers
  2. import (
  3. "strconv"
  4. log "github.com/sirupsen/logrus"
  5. )
  6. func Atof(x string) float64 {
  7. log.Debugf("debug atof %s", x)
  8. ret, err := strconv.ParseFloat(x, 64)
  9. if err != nil {
  10. log.Warningf("Atof : can't convert float '%s' : %v", x, err)
  11. }
  12. return ret
  13. }
  14. func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
  15. var ExprLib = map[string]interface{}{"Atof": Atof, "JsonExtract": JsonExtract, "JsonExtractLib": JsonExtractLib}
  16. for k, v := range ctx {
  17. ExprLib[k] = v
  18. }
  19. return ExprLib
  20. }