diff --git a/pkg/config/config.go b/pkg/config/config.go index 09ca557..fbac538 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -75,7 +75,7 @@ func FromFlags(progName string, args []string) (Config, string, error) { flags.StringVar(&c.OutputFormat, "output", "text", "output format - json, tap, text") flags.BoolVar(&c.Verbose, "verbose", false, "print results for all resources") flags.BoolVar(&c.SkipTLS, "insecure-skip-tls-verify", false, "disable verification of the server's SSL certificate. This will make your HTTPS connections insecure") - flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file") + //flags.StringVar(&c.CPUProfileFile, "cpu-prof", "", "debug - log CPU profiling to file") flags.BoolVar(&c.Help, "h", false, "show help information") flags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [OPTION]... [FILE OR FOLDER]...\n", progName) diff --git a/pkg/resource/files.go b/pkg/resource/files.go index 6b443ac..81cf272 100644 --- a/pkg/resource/files.go +++ b/pkg/resource/files.go @@ -42,6 +42,7 @@ func isIgnored(path string, ignoreFilePatterns []string) (bool, error) { func FromFiles(ctx context.Context, ignoreFilePatterns []string, paths ...string) (<-chan Resource, <-chan error) { resources := make(chan Resource) + files := make(chan string) errors := make(chan error) go func() { @@ -71,27 +72,7 @@ func FromFiles(ctx context.Context, ignoreFilePatterns []string, paths ...string return nil } - f, err := os.Open(p) - if err != nil { - return err - } - - scanner := bufio.NewScanner(f) - const maxResourceSize = 4 * 1024 * 1024 // 4MB ought to be enough for everybody - buf := make([]byte, maxResourceSize) - scanner.Buffer(buf, maxResourceSize) - scanner.Split(SplitYAMLDocument) - nRes := 0 - for res := scanner.Scan(); res != false; res = scanner.Scan() { - resources <- Resource{Path: p, Bytes: scanner.Bytes()} - nRes++ - } - if err := scanner.Err(); err != nil { - errors <- DiscoveryError{p, err} - } - if nRes == 0 { - resources <- Resource{Path: p, Bytes: []byte{}} - } + files <- p return nil }) @@ -101,6 +82,35 @@ func FromFiles(ctx context.Context, ignoreFilePatterns []string, paths ...string } } + close(files) + }() + + go func() { + maxResourceSize := 4 * 1024 * 1024 + buf := make([]byte, maxResourceSize) + + for p := range files { + f, err := os.Open(p) + if err != nil { + errors <- DiscoveryError{p, err} + } + + scanner := bufio.NewScanner(f) + scanner.Buffer(buf, maxResourceSize) + scanner.Split(SplitYAMLDocument) + nRes := 0 + for res := scanner.Scan(); res != false; res = scanner.Scan() { + resources <- Resource{Path: p, Bytes: []byte(scanner.Text())} + nRes++ + } + if err := scanner.Err(); err != nil { + errors <- DiscoveryError{p, err} + } + if nRes == 0 { + resources <- Resource{Path: p, Bytes: []byte{}} + } + } + close(resources) close(errors) }()