fix: 修复 file.ReadOnce 读文件错误
采用 defer 修复由于提前关闭文件导致无法读取文件数据的问题
This commit is contained in:
parent
a4e9b5f143
commit
b0ae56991b
|
@ -48,7 +48,9 @@ func ReadOnce(filePath string) ([]byte, error) {
|
||||||
if file, err := os.Open(filePath); err != nil {
|
if file, err := os.Open(filePath); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
_ = file.Close()
|
defer func() {
|
||||||
|
_ = file.Close()
|
||||||
|
}()
|
||||||
return io.ReadAll(file)
|
return io.ReadAll(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue