Andrew's Digital Garden

Defer in Go

The defer statement allows to delay a function call until the point where the calling function exits. This is very handy for cleaning up resources, like closing all open files, regardless of where and why the calling function exits.

[[go]]

Defer in Go