exprlib.go 640 B

12345678910111213141516171819202122232425262728293031323334
  1. package exprhelpers
  2. import (
  3. "strconv"
  4. "strings"
  5. log "github.com/sirupsen/logrus"
  6. )
  7. func Atof(x string) float64 {
  8. log.Debugf("debug atof %s", x)
  9. ret, err := strconv.ParseFloat(x, 64)
  10. if err != nil {
  11. log.Warningf("Atof : can't convert float '%s' : %v", x, err)
  12. }
  13. return ret
  14. }
  15. func StartsWith(s string, pref string) bool {
  16. return strings.HasPrefix(s, pref)
  17. }
  18. func EndsWith(s string, suff string) bool {
  19. return strings.HasSuffix(s, suff)
  20. }
  21. func GetExprEnv(ctx map[string]interface{}) map[string]interface{} {
  22. var ExprLib = map[string]interface{}{"Atof": Atof}
  23. for k, v := range ctx {
  24. ExprLib[k] = v
  25. }
  26. return ExprLib
  27. }