Skip to content

Commit

Permalink
Do not fully read files before processing them for slightly better pe…
Browse files Browse the repository at this point in the history
…rformance
  • Loading branch information
Nitive committed Jul 25, 2020
1 parent fc39fbb commit 4fa9c76
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -93,19 +92,20 @@ func main() {
go func(fileName string, i int) {
defer wg.Done()

fileContext, err := ioutil.ReadFile(fileName)
var config Kubeconfig
file, err := os.Open(fileName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading %s %v", fileName, err)
fmt.Fprintf(os.Stderr, "Error opening file %s %v", fileName, err)
return
}

var config Kubeconfig
err = yaml.Unmarshal(fileContext, &config)
err = yaml.NewDecoder(file).Decode(&config)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing %s %v", fileName, err)
return
}

file.Close()
parsedKubeconfigs[i] = config
}(file, i)
}
Expand Down

0 comments on commit 4fa9c76

Please sign in to comment.