defer是延迟执行。如果存在多个defer,运行顺序是先进后出,属于堆栈结构
f, err := os.Create(fileName)
if err != nil {
fmt.Println("Create file failed:", err)
return nil, err
}
defer os.Remove(fileName)
defer f.Close()
2024-03-07 18:33:03
defer是延迟执行。如果存在多个defer,运行顺序是先进后出,属于堆栈结构
f, err := os.Create(fileName)
if err != nil {
fmt.Println("Create file failed:", err)
return nil, err
}
defer os.Remove(fileName)
defer f.Close()