From b4f15ff814eeaa8f0c74b60b6f64f02adfbc9fff Mon Sep 17 00:00:00 2001 From: zhongjiajia Date: Sat, 4 Jun 2022 00:51:51 +0800 Subject: [PATCH] Fixed WriteFile and ReadFile --- pkg/tools/common.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/tools/common.go b/pkg/tools/common.go index e201802..970cc09 100644 --- a/pkg/tools/common.go +++ b/pkg/tools/common.go @@ -27,10 +27,10 @@ func ConvertHeaders(h map[string]interface{}) map[string]string { func WriteFile(fileName string, content []byte) { f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE, 0644) - defer f.Close() if err != nil { fmt.Println(err.Error()) } else { + defer f.Close() _, err = f.Write(content) if err != nil { logger.Logger.Error("write to file error ", err) @@ -41,10 +41,10 @@ func WriteFile(fileName string, content []byte) { func ReadFile(filePath string) []string { filePaths := []string{} f, err := os.OpenFile(filePath, os.O_RDONLY, 0644) - defer f.Close() if err != nil { fmt.Println(err.Error()) } else { + defer f.Close() rd := bufio.NewReader(f) for { line, err := rd.ReadString('\n')