In Go, defer statements delay the execution of the function until the nearby functions returns. Defer function call arguments evaluate instantly, but they execute until the nearby functions returns.
You can create a deferred method, or function, or anonymous function by using the defer keyword.
<pre><code>// Function
defer func func_name(parameter_list Type)return_type{
// Code
}
// Method
defer func (receiver Type) method_name(parameter_list){
// Code
}
defer func (parameter_list)(return_type){
// code
}()
</code></pre>