entities.go 668 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }
  22. func RemoveKeysThatStartWith(search string) {
  23. for k, _ := range Contents {
  24. if strings.HasPrefix(k, search) {
  25. delete(Contents, k)
  26. }
  27. }
  28. }