defer closing file when loading data

This commit is contained in:
2022-03-20 02:20:13 +01:00
parent 0e5a3d7361
commit 91709e65bd

View File

@@ -89,7 +89,10 @@ func loadFile(ty string, currentDomain *domain) {
f, err := os.Open(filePath)
if err != nil {
color.Warnf("Could not load file for domain %s: %s\n", currentDomain.Root, err)
} else {
return
}
defer f.Close()
log.Printf("Reading file: %s", filePath)
scanner := bufio.NewScanner(f)
@@ -111,8 +114,6 @@ func loadFile(ty string, currentDomain *domain) {
}
color.Infof("Read file: %s\n", filePath)
}
f.Close()
}
func Init(dataPath string) {
currentDataPath = dataPath