We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Defer Functions In Golang: Everything You Need To Know
Summary
Description
The defer keyword in Go is a powerful feature you must know! Structs are also really common in Golang and that's why I highly recommend watching this video here as well: https://youtu.be/c8H0w4yBL10
📝 Description
In this video, we dive deep into one of the most useful and powerful features in Golang—the defer keyword. This concept allows for deferred processing that executes a function just before it returns, making it especially useful for cleanup operations or handling panics. We'll look into three different use-cases: reading a file, logging the execution time of a function, and handling and recovering from panics. Each example will provide you with practical knowledge on how to use the defer keyword effectively in your Golang code.
⏳ Timestamps:
00:00 - Definition of defer
01:37 - 1. Use case - Reading a file
05:55 - 2. Use case - Benchmarking a function
09:39 - 3. Use case - Recover from panics
11:52 - Outro
👋 Hey there!
If you are new to this channel: Hey 👋 my name is Flo and I am a professional software engineer with a passion for coding in Golang, TypeScript, JavaScript, and Rust. This channel is where I share that passion and dive into the exciting world of software engineering. Plus, I love using Emojis and paper-based animations (so have a look for that, if you want to find my videos).
📨 Support and Connect!
Buy me a coffee: https://www.buymeacoffee.com/florianwoelki
Become a member. https://www.youtube.com/@FloWoelki/membership
Discord: https://discord.gg/TnA7drJ
X / Twitter: https://x.com/FlorianWoelki
LinkedIn: https://www.linkedin.com/in/florian-woelki/
GitHub: https://github.com/FlorianWoelki
📝 Copyright Notice
The original Go Gopher version is originally designed by Renée French (Source: https://go.dev/blog/gopher License details: https://creativecommons.org/licenses/by/4.0/). The gopher used in the video and thumbnail is inspired by this author.
#golang #go #defer
Translated At: 2025-08-05T13:28:22Z