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 +}