6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-30 18:51:03 +00:00
prologic-saltyim/cmd/salty-chat/utils.go
2022-03-24 01:41:36 +10:00

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
}