增加文件写入操作

This commit is contained in:
白茶清欢 2022-05-22 15:52:01 +08:00
parent c3c29411dc
commit c6ccad2e3a

17
file.go
View File

@ -34,7 +34,7 @@ func File(workDir string, filePath string) *fileOperate {
workDir: workDir, workDir: workDir,
filePath: filePath, filePath: filePath,
permission: 0644, permission: 0644,
openFlag: os.O_RDONLY, openFlag: os.O_RDWR, // 默认以读写模式打开
} }
} }
@ -198,3 +198,18 @@ func (f *fileOperate) ReadForYaml(receiver interface{}) error {
decoder.SetStrict(true) decoder.SetStrict(true)
return decoder.Decode(receiver) 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
}