learn go defer

package main

// 参考文档:
//     https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.4.md

import "fmt"

func main() {
    function1()
}

func function1() {
    fmt.Printf("In function1 at the top
")
    defer function2()
    fmt.Printf("In function1 at the buttom
")
}

func function2() {
    fmt.Printf("function2: Deferred until the end of the calling function!
")
}
原文地址:https://www.cnblogs.com/zengjfgit/p/4986280.html