Initial commit.

This commit is contained in:
2020-07-16 06:24:19 +00:00
commit ec780df92f
15 changed files with 735 additions and 0 deletions

34
lib/util/file.go Normal file
View File

@ -0,0 +1,34 @@
package util
import (
"io/ioutil"
"log"
"path/filepath"
)
type ParseFunc func(data []byte) int
func ParseFiles(dir string, parser ParseFunc) {
files, err := ioutil.ReadDir(dir)
if err != nil {
log.Print(err.Error())
return
}
for _, file := range files {
if filepath.Ext(file.Name()) == ".yml" || filepath.Ext(file.Name()) == ".yaml" {
ParseFile(dir+file.Name(), parser)
}
}
}
func ParseFile(fileName string, parser ParseFunc) {
data, err := ioutil.ReadFile(fileName)
if err != nil {
log.Print(err.Error())
return
}
count := parser(data)
log.Printf("util.parseFile: Added %d new entries from %s", count, fileName)
}