Files
revsuit/internal/rule/compile.go
T
2021-05-05 12:59:50 +08:00

21 lines
432 B
Go

package rule
import (
"strings"
)
// CompileTpl receive []byte or string type tpl and variables map.
// Return the template after variable substitution
func CompileTpl(tpl interface{}, vars map[string]string) (compiled string) {
switch v := tpl.(type) {
case string:
compiled = v
case []byte:
compiled = string(v)
}
for n, v := range vars {
compiled = strings.ReplaceAll(compiled, "${"+n+"}", v)
}
return compiled
}