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

44 lines
864 B

2 years ago
package gotxt
import (
"context"
"fmt"
text "text/template"
"gitoa.ru/go-4devs/templating"
"gitoa.ru/go-4devs/templating/engine"
gotxt "gitoa.ru/go-4devs/templating/gotxt/engine"
"gitoa.ru/go-4devs/templating/loader"
)
const Name = gotxt.Name
var txt = gotxt.New()
func init() {
templating.AddEngine(txt)
}
// Loader set new loader. This function is not thread-safe.
func Loader(in loader.Loader) {
txt = txt.WithLoader(in)
}
func Must(template *text.Template, err error) {
MustRegister(text.Must(template, err))
}
func MustRegister(template *text.Template) {
if rerr := Register(template); rerr != nil {
panic(rerr)
}
}
func Register(template *text.Template) error {
if err := txt.Add(context.Background(), engine.NewTemplate(template.Name(), template.Execute)); err != nil {
return fmt.Errorf("gotext loader:%w", err)
}
return nil
}