You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
501 B
Go

package layout
import (
"bytes"
"text/template"
)
var _ Template = TextTemplate{}
type TextTemplate struct {
*template.Template
}
func NewTextTemplate(files ...string) (*TextTemplate, error) {
t, err := template.ParseFiles(files...)
if err != nil {
return nil, err
}
return &TextTemplate{t}, nil
}
func (t TextTemplate) Render(ctx map[string]any) ([]byte, error) {
var b bytes.Buffer
if err := t.Template.Execute(&b, ctx); err != nil {
return nil, err
}
return b.Bytes(), nil
}