func process() {
// open file to write
f, err := os.Create(fName)
if err != nil {
fmt.Println(err)
f.Close()
return
}
defer f.Close()
if true {
//for some reason we need to discard file creation
//if to delete file from this line will then `defer` be executed?
return
}
...
}
Maybe there is a better aproach to discard file creaton?
I foud out that I must explicitely execute f.Close() before deleting the file because in other case I get “the file cann’t be deleted because it used by another process”.