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.
38 lines
652 B
38 lines
652 B
package templating
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"sync"
|
|
|
|
"gitoa.ru/go-4devs/templating/parser"
|
|
"gitoa.ru/go-4devs/templating/render"
|
|
)
|
|
|
|
var (
|
|
exec = render.New(parser.Name)
|
|
mu = sync.Mutex{}
|
|
)
|
|
|
|
func SetParser(parser render.Parser) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
exec = exec.WithParser(parser)
|
|
}
|
|
|
|
func AddEngine(engine ...render.Engine) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
exec.Add(engine...)
|
|
}
|
|
|
|
func Execute(ctx context.Context, wr io.Writer, name string, data interface{}, opts ...render.Option) error {
|
|
if err := exec.Execute(ctx, wr, name, data, opts...); err != nil {
|
|
return fmt.Errorf("templating engine:%w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|