fix: 覆盖写入字符串到文件问题 (#128)

This commit is contained in:
ggymm authored and GitHub committed 2023-08-24 16:36:44 +08:00
1 parent 91bc1a512c
commit e66ab154bc
2 files changed
+21 -9

No files matched your search

+4 -2
View File
@@ -594,9 +594,11 @@ func WriteCsvFile(filepath string, records [][]string, append bool) error {
// WriteStringToFile write string to target file.
// Play: https://go.dev/play/p/GhLS6d8lH_g
func WriteStringToFile(filepath string, content string, append bool) error {
flag := os.O_RDWR | os.O_CREATE
var flag int
if append {
flag = flag | os.O_APPEND
flag = os.O_RDWR | os.O_CREATE | os.O_APPEND
} else {
flag = os.O_RDWR | os.O_CREATE | os.O_TRUNC
}
f, err := os.OpenFile(filepath, flag, 0644)