1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 17:30:56 +00:00

fix(Template): close open file

This commit is contained in:
Viktor Vassilyev 2018-11-05 22:51:20 +06:00
parent f740b71ded
commit 2f00ad1602

View File

@ -185,13 +185,13 @@ func BuildTemplate(dir string, files ...string) error {
var err error var err error
fs := beeTemplateFS() fs := beeTemplateFS()
f, err := fs.Open(dir) f, err := fs.Open(dir)
defer f.Close()
if err != nil { if err != nil {
if os.IsNotExist(err) { if os.IsNotExist(err) {
return nil return nil
} }
return errors.New("dir open err") return errors.New("dir open err")
} }
defer f.Close()
beeTemplates, ok := beeViewPathTemplates[dir] beeTemplates, ok := beeViewPathTemplates[dir]
if !ok { if !ok {
@ -247,6 +247,7 @@ func getTplDeep(root string, fs IFileSystem, file string, parent string, t *temp
fileAbsPath = filepath.Join(root, file) fileAbsPath = filepath.Join(root, file)
} }
f, err := fs.Open(fileAbsPath) f, err := fs.Open(fileAbsPath)
defer f.Close()
if err != nil { if err != nil {
panic("can't find template file:" + file) 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) fileAbsPath := filepath.Join(root, otherFile)
f, err := fs.Open(fileAbsPath) f, err := fs.Open(fileAbsPath)
if err != nil { if err != nil {
f.Close()
continue continue
} }
data, err = ioutil.ReadAll(f) data, err = ioutil.ReadAll(f)
f.Close()
reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"") reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"")
allSub := reg.FindAllStringSubmatch(string(data), -1) allSub := reg.FindAllStringSubmatch(string(data), -1)
for _, sub := range allSub { for _, sub := range allSub {