mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-23 19:57:02 +00:00
Factor out isYaml
This commit is contained in:
parent
9ee3c5f07f
commit
2391d82281
1 changed files with 9 additions and 6 deletions
|
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue