Allow zero matching template files

This commit is contained in:
Fabian Reinartz 2015-12-09 14:51:18 +01:00
parent f8fdb24fb2
commit 76f884b328
1 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,7 @@ package template
import (
"bytes"
"net/url"
"path/filepath"
"sort"
"strings"
@ -60,6 +61,13 @@ func FromGlobs(paths ...string) (*Template, error) {
}
for _, tp := range paths {
// ParseGlob in the template packages errors if not at least one file is
// matched. We want to allow empty matches that may be populated later on.
p, err := filepath.Glob(tp)
if err != nil {
return nil, err
}
if len(p) > 0 {
if t.text, err = t.text.ParseGlob(tp); err != nil {
return nil, err
}
@ -67,6 +75,7 @@ func FromGlobs(paths ...string) (*Template, error) {
return nil, err
}
}
}
return t, nil
}