mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-19 02:19:52 +00:00
Refactor resource discovery
This commit is contained in:
parent
2391d82281
commit
0a7f885768
4 changed files with 78 additions and 139 deletions
|
|
@ -6,17 +6,24 @@ import (
|
|||
"io/ioutil"
|
||||
)
|
||||
|
||||
func FromStream(path string, r io.Reader) ([]Resource, error) {
|
||||
data, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
return []Resource{}, err
|
||||
}
|
||||
func FromStream(path string, r io.Reader) (<-chan Resource, <-chan error) {
|
||||
resources := make(chan Resource)
|
||||
errors := make(chan error)
|
||||
|
||||
resources := []Resource{}
|
||||
rawResources := bytes.Split(data, []byte("---\n"))
|
||||
for _, rawResource := range rawResources {
|
||||
resources = append(resources, Resource{Path: path, Bytes: rawResource})
|
||||
}
|
||||
go func() {
|
||||
data, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
errors <- DiscoveryError{path, err}
|
||||
}
|
||||
|
||||
return resources, nil
|
||||
rawResources := bytes.Split(data, []byte("---\n"))
|
||||
for _, rawResource := range rawResources {
|
||||
resources <- Resource{Path: path, Bytes: rawResource}
|
||||
}
|
||||
|
||||
close(resources)
|
||||
close(errors)
|
||||
}()
|
||||
|
||||
return resources, errors
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue