2020-12-24 12:56:28 +05:30
|
|
|
package replacer
|
|
|
|
|
|
|
|
|
|
import (
|
2021-02-04 04:48:45 +05:30
|
|
|
"github.com/valyala/fasttemplate"
|
2020-12-24 12:56:28 +05:30
|
|
|
)
|
|
|
|
|
|
2020-12-28 01:33:50 +05:30
|
|
|
// Payload marker constants
|
2020-12-24 12:56:28 +05:30
|
|
|
const (
|
2020-12-28 01:33:50 +05:30
|
|
|
MarkerGeneral = "§"
|
|
|
|
|
MarkerParenthesisOpen = "{{"
|
|
|
|
|
MarkerParenthesisClose = "}}"
|
2020-12-24 12:56:28 +05:30
|
|
|
)
|
|
|
|
|
|
2021-02-04 04:48:45 +05:30
|
|
|
// Replace replaces placeholders in template with values on the fly.
|
|
|
|
|
func Replace(template string, values map[string]interface{}) string {
|
2021-02-26 13:13:11 +05:30
|
|
|
newResult := fasttemplate.ExecuteStringStd(template, MarkerGeneral, MarkerGeneral, values)
|
|
|
|
|
final := fasttemplate.ExecuteStringStd(newResult, MarkerParenthesisOpen, MarkerParenthesisClose, values)
|
2021-02-04 04:48:45 +05:30
|
|
|
return final
|
2020-12-24 12:56:28 +05:30
|
|
|
}
|