Simple Go defer code example
In Go, a defer statement will execute a function call just before the function it is called from returns.
I found that most of the examples of a Go defer call online seemed to do complicated things with numbers. So here is a nice simple example with just text output.
You can run this code yourself in The Go Playground! You can also find a similar example in the Go Tour.
One Four Three Two
If you get something else, you’re doing something wrong ;)
[…] can probably do some of this cleanup using defer, but I skipped that in this example for […]