in filesource.go [69:87]
func (s *SourceFS) Template(path string) FileContent {
return func(_ context.Context, scope Scope, w io.Writer) error {
fmap := template.FuncMap{
"fact": func(name string) (string, error) {
v, found := scope.Fact(name)
if !found {
return "", fmt.Errorf("fact %q not found", name)
}
return v, nil
},
}
t, err := template.New(filepath.Base(path)).Funcs(s.templateFuncs).Funcs(fmap).ParseFS(s.FS, path)
if err != nil {
return err
}
return t.Execute(w, nil)
}
}