Factor out isYaml

This commit is contained in:
Yann Hamon 2020-11-01 16:50:16 +01:00
parent 9ee3c5f07f
commit 2391d82281

View file

@ -6,19 +6,22 @@ import (
"strings" "strings"
) )
func isYaml(info os.FileInfo) bool {
return !info.IsDir() && (strings.HasSuffix(strings.ToLower(info.Name()), ".yaml") || strings.HasSuffix(strings.ToLower(info.Name()), ".yml"))
}
// FindYamlInDir will find yaml files in folder dir, and send their filenames in batches // FindYamlInDir will find yaml files in folder dir, and send their filenames in batches
// of size batchSize to channel fileBatches // of size batchSize to channel fileBatches
func FindYamlInDir(dir string, fileBatches chan<- string) error { func FindYamlInDir(dir string, files chan<- string) error {
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }
if !info.IsDir() && (strings.HasSuffix(info.Name(), ".yaml") || strings.HasSuffix(info.Name(), ".yml")) { if isYaml(info) {
fileBatches <- path files <- path
} }
return nil return nil
}) })
return err
} }