In this blog post we’ll be exploring the powerful combination of using go’s builtin defer statement and named return values.
Individually defer is great almost all the time; however, name returned values in my opinion are a bit of a problem child, I rarely use them, but in certain cases as the one I’m about to show you I find them helpful.
Let’s look at the use case.
Let’s say we are working on an API that has some async tasks, for example, a speech-to-text action given an mp3 file.