From c6c415ffb3d84b863ea8cbda6692023d042dad32 Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Thu, 12 Oct 2023 11:09:05 +0800 Subject: [PATCH] fix: check returned error before deferring file.Close() --- pkg/file/file.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/file/file.go b/pkg/file/file.go index 0c4a108..e1c3656 100644 --- a/pkg/file/file.go +++ b/pkg/file/file.go @@ -12,10 +12,10 @@ import ( func ReadingLines(filename string) []string { var result []string file, err := os.Open(filename) - defer file.Close() if err != nil { return result } + defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() {