Skip to content

Avoid some unnecessary buffering when reading config file #2215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ func readConfig(stderr io.Writer, dir, filename string) (string, *config.Config,
}

base := filepath.Base(configPath)
blob, err := os.ReadFile(configPath)
file, err := os.Open(configPath)
if err != nil {
fmt.Fprintf(stderr, "error parsing %s: file does not exist\n", base)
return "", nil, err
}
defer file.Close()

conf, err := config.ParseConfig(bytes.NewReader(blob))
conf, err := config.ParseConfig(file)
if err != nil {
switch err {
case config.ErrMissingVersion:
Expand Down