Go: Defer Keyword

You can create a deferred method, or function, or anonymous function by using the defer keyword.

// 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
}()

Leave a Reply

Your email address will not be published. Required fields are marked *