From c6ccad2e3a3f1decd7e6a94c1329f0af8dbd1fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 22 May 2022 15:52:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- file.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/file.go b/file.go index 39e12a7..307aa2b 100644 --- a/file.go +++ b/file.go @@ -34,7 +34,7 @@ func File(workDir string, filePath string) *fileOperate { workDir: workDir, filePath: filePath, permission: 0644, - openFlag: os.O_RDONLY, + openFlag: os.O_RDWR, // 默认以读写模式打开 } } @@ -198,3 +198,18 @@ func (f *fileOperate) ReadForYaml(receiver interface{}) error { decoder.SetStrict(true) return decoder.Decode(receiver) } + +// Write 想文件写入内容 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 15:47 2022/5/22 +func (f *fileOperate) Write(content []byte) error { + if nil == f.fileHandler { + if err := f.Open(); nil != err { + return errors.New("文件打开失败 : " + err.Error()) + } + } + _, writeErr := f.fileHandler.Write(content) + return writeErr +}