From 2f00ad16023f29da3dff9a1222d7db5d7bafabdf Mon Sep 17 00:00:00 2001 From: Viktor Vassilyev Date: Mon, 5 Nov 2018 22:51:20 +0600 Subject: [PATCH] fix(Template): close open file --- template.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/template.go b/template.go index 45d73fa0..3321d13f 100644 --- a/template.go +++ b/template.go @@ -185,13 +185,13 @@ func BuildTemplate(dir string, files ...string) error { var err error fs := beeTemplateFS() f, err := fs.Open(dir) + defer f.Close() if err != nil { if os.IsNotExist(err) { return nil } return errors.New("dir open err") } - defer f.Close() beeTemplates, ok := beeViewPathTemplates[dir] if !ok { @@ -247,6 +247,7 @@ func getTplDeep(root string, fs IFileSystem, file string, parent string, t *temp fileAbsPath = filepath.Join(root, file) } f, err := fs.Open(fileAbsPath) + defer f.Close() if err != nil { panic("can't find template file:" + file) } @@ -320,9 +321,11 @@ func _getTemplate(t0 *template.Template, root string, fs IFileSystem, subMods [] fileAbsPath := filepath.Join(root, otherFile) f, err := fs.Open(fileAbsPath) if err != nil { + f.Close() continue } data, err = ioutil.ReadAll(f) + f.Close() reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"") allSub := reg.FindAllStringSubmatch(string(data), -1) for _, sub := range allSub {