Defering execution of code is commonly used in Go to clean up resources. It's not so often seen but happens that defer
is used to execute regular business logic, too. Just as a last step of execution, no matter at which point function hits return
keyword.
On Go Blog page, we can find that "defer statement pushes a function call onto a list. The list of saved calls is executed after the surrounding function returns. Defer is commonly used to simplify functions that perform various clean-up actions."
They do mention about cleaning up but nothing about regular code execution. Obviously, it may execute an arbitrary code, doesn't have to be cleaning up. Is this the best practice, though? Has community any agreement on convention or best practice in this regard?