init template

This commit is contained in:
andrey1s
2022-10-02 23:31:19 +03:00
parent 3d5d51b2df
commit 621afcc59c
24 changed files with 969 additions and 0 deletions

29
loader/chain/loader.go Normal file
View File

@@ -0,0 +1,29 @@
package chain
import (
"context"
"errors"
"fmt"
"gitoa.ru/go-4devs/templating/loader"
"gitoa.ru/go-4devs/templating/render"
)
var _ loader.Loader = (Loaders)(nil)
type Loaders []loader.Loader
func (l Loaders) Load(ctx context.Context, template render.Reference) (loader.Source, error) {
for idx, load := range l {
sourse, err := load.Load(ctx, template)
if err == nil {
return sourse, nil
}
if !errors.Is(err, loader.ErrNotFound) {
return loader.Source{}, fmt.Errorf("chain[%d]:%w", idx, err)
}
}
return loader.Source{}, fmt.Errorf("chains(%d):%w", len(l), loader.ErrNotFound)
}