mirror of
https://github.com/Li4n0/revsuit.git
synced 2026-09-22 06:40:43 +08:00
21 lines
432 B
Go
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
|
|
}
|