entities.go 524 B

1234567891011121314151617181920212223242526272829
  1. package stringvariables
  2. import (
  3. "regexp"
  4. "strings"
  5. // log "github.com/sirupsen/logrus"
  6. )
  7. var r *regexp.Regexp
  8. func init() {
  9. r = regexp.MustCompile("{{ *?([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_]+) *?}}")
  10. }
  11. func ReplaceEntityVars(prefix string, source string) string {
  12. matches := r.FindAllStringSubmatch(source, -1)
  13. for _, matches := range matches {
  14. if len(matches) == 3 {
  15. property := matches[2]
  16. val := Get(prefix + "." + property)
  17. source = strings.Replace(source, matches[0], val, 1)
  18. }
  19. }
  20. return source
  21. }