improve fileInit func by not loading unspecified data (#189)

* improve fileInit func by not loading unsepcified data
This commit is contained in:
erenJag 2020-08-21 14:20:44 +02:00 committed by GitHub
parent 5595070e67
commit 25dfcebf4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -60,12 +60,13 @@ func FileInit(fileFolder string, filename string, fileType string) error {
}
defer file.Close()
if fileType == "" {
log.Debugf("ignored file %s%s because no type specified", fileFolder, filename)
return nil
}
if _, ok := dataFile[filename]; !ok {
dataFile[filename] = []string{}
}
if fileType == "" {
fileType = "string"
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), "#") { // allow comments

View file

@ -165,7 +165,7 @@ func TestFile(t *testing.T) {
log.Fatalf(err.Error())
}
err := FileInit(TestFolder, "test_data.txt", "")
err := FileInit(TestFolder, "test_data.txt", "string")
if err != nil {
log.Fatalf(err.Error())
}