Skip to content

Glossary: Software Design Patterns in Go

defer

Also written: defer f.Close()

A Go keyword that schedules a call to run when the surrounding function ends, such as `defer f.Close()` right after `os.Open`. It works like a template method because the closing step is fixed and always runs.

Where the book teaches it

Related terms

Template method