Error checking and defer in Go

An important rule in Go is that you should always check errors. Most people have no issues with that and are correctly checking all their errors, except when the error might come from a deferred method. This code, for example, is something fairly common in many codebases:

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

Staff Engineer at Abstract, Splice. I love Go, and I love Git. https://melvin.lahttps://linkedin.com/in/melvinlaplanchehttps://github.com/Nivl

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store