mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-13 01:25:45 +00:00
feature: The mega dashboards & entities commit.
This commit is contained in:
29
internal/stringvariables/entities.go
Normal file
29
internal/stringvariables/entities.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package stringvariables
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
// log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var r *regexp.Regexp
|
||||
|
||||
func init() {
|
||||
r = regexp.MustCompile("{{ *?([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_]+) *?}}")
|
||||
}
|
||||
|
||||
func ReplaceEntityVars(prefix string, source string) string {
|
||||
matches := r.FindAllStringSubmatch(source, -1)
|
||||
|
||||
for _, matches := range matches {
|
||||
if len(matches) == 3 {
|
||||
property := matches[2]
|
||||
|
||||
val := Get(prefix + "." + property)
|
||||
|
||||
source = strings.Replace(source, matches[0], val, 1)
|
||||
}
|
||||
}
|
||||
|
||||
return source
|
||||
}
|
||||
Reference in New Issue
Block a user