Go defer
The defer statement schedules a function call to run when the surrounding function returns. Deferred calls execute in last-in, first-out order, making defer useful for cleanup such as closing files or releasing resources.
Minimal example
func printOrder() {
defer fmt.Println("third")
defer fmt.Println("second")
fmt.Println("first")
}