This article is more about tricks rather than gotchas of defer.
Read the following posts from this series to discover more gotchas and tricks about defer:
If you don’t know how defer works please read this starter post first:
In this article I’m going to cover what happened in 2017 and what will happen in 2018. And also, I’ve created a path for you to follow, so you can read my articles in order to digest them easily.
After working days, nights, weeks, weekends, and months fulltime educating people about Go for 3 months, this happened:
We’re continuing our journey of defer gotchas.
This can become a gotcha when you’re learning Go for the first time.
🐼 This article is only for beginner to intermediate level Gophers, masters: “close the tab please”.
If a deferred func evaluates to
nil, execution panics when the surrounding func ends not when defer is called.
Alright, that’s all for now. Thank you for reading so far.
This post is a summary for the different kind of funcs in Go. I’ll go into more detail in the upcoming posts because they deserve more. This is just a start.
A variadic func accepts variable number of input values — zero or more. Ellipsis (three-dots) prefix in front of an input type makes a func variadic.
Note: This guide is only about introducing Go functions, not about: variadic, defer, and external funcs; or methods, http, and marshaling, etc.
A function is a separate and reusable block of code which can be run again and again. Functions may accept input values and they may return output values.