From 963a6976d1c2d8f63a3a1be29b3f482151655960 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 24 Aug 2023 00:08:38 +0300 Subject: [PATCH] refactor: use os.ReadFile instead of os.Open + io.ReadAll (#1254) --- detect/baseline.go | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/detect/baseline.go b/detect/baseline.go index b1efb458c..7a8cd5b70 100644 --- a/detect/baseline.go +++ b/detect/baseline.go @@ -3,11 +3,8 @@ package detect import ( "encoding/json" "fmt" - "io" "os" - "github.com/rs/zerolog/log" - "github.com/zricethezav/gitleaks/v8/report" ) @@ -39,23 +36,12 @@ func IsNew(finding report.Finding, baseline []report.Finding) bool { } func LoadBaseline(baselinePath string) ([]report.Finding, error) { - var previousFindings []report.Finding - jsonFile, err := os.Open(baselinePath) + bytes, err := os.ReadFile(baselinePath) if err != nil { return nil, fmt.Errorf("could not open %s", baselinePath) } - defer func() { - if cerr := jsonFile.Close(); cerr != nil { - log.Warn().Err(cerr).Msg("problem closing jsonFile handle") - } - }() - - bytes, err := io.ReadAll(jsonFile) - if err != nil { - return nil, fmt.Errorf("could not read data from the file %s", baselinePath) - } - + var previousFindings []report.Finding err = json.Unmarshal(bytes, &previousFindings) if err != nil { return nil, fmt.Errorf("the format of the file %s is not supported", baselinePath)