mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-30 18:51:03 +00:00
28 lines
515 B
Go
28 lines
515 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"text/template"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func renderString(s string, ctx interface{}) (string, error) {
|
|
t := template.Must(template.New("s").Parse(s))
|
|
buf := bytes.NewBuffer([]byte{})
|
|
err := t.Execute(buf, ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|
|
|
|
func mustRenderString(s string, ctx interface{}) string {
|
|
out, err := renderString(s, ctx)
|
|
if err != nil {
|
|
log.WithError(err).Fatal("error rendering string template")
|
|
}
|
|
return out
|
|
}
|