From 76f884b3284f044491f79d573d01dd09500854f7 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 9 Dec 2015 14:51:18 +0100 Subject: [PATCH] Allow zero matching template files --- template/template.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/template/template.go b/template/template.go index 9db0dd4a..52f18b4c 100644 --- a/template/template.go +++ b/template/template.go @@ -16,6 +16,7 @@ package template import ( "bytes" "net/url" + "path/filepath" "sort" "strings" @@ -60,11 +61,19 @@ func FromGlobs(paths ...string) (*Template, error) { } for _, tp := range paths { - if t.text, err = t.text.ParseGlob(tp); err != nil { + // 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 t.html, err = t.html.ParseGlob(tp); err != nil { - return nil, err + if len(p) > 0 { + if t.text, err = t.text.ParseGlob(tp); err != nil { + return nil, err + } + if t.html, err = t.html.ParseGlob(tp); err != nil { + return nil, err + } } } return t, nil