according to https://www.joeshaw.org/dont-defer-close-on-writable-files/ one should not use defer file.close(), its a bad pattern

This commit is contained in:
Maciek Niemczyk 2019-06-17 14:25:41 +02:00
parent 46fe6bc6cb
commit 3b153c7d80

View File

@ -40,5 +40,9 @@ func writeFile(f *os.File) {
func closeFile(f *os.File) {
fmt.Println("closing")
f.Close()
err := f.Close()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}