Defer Functions In Golang: Everything You Need To Know

Published: 31 May 2024
on channel: Flo Woelki
1,448
91

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:    • This is your last video about Golang ...  


📝 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/florianw...
Become a member:    / @flowoelki  
Discord:   / discord  
Instagram:   / flowydev  
LinkedIn:   / florian-woelki  
TikTok:   / florianwoelki  
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/.... The gopher used in the video and thumbnail is inspired by this author.


#golang #go #defer


Watch video Defer Functions In Golang: Everything You Need To Know online without registration, duration hours minute second in high quality. This video was added by user Flo Woelki 31 May 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,448 once and liked it 91 people.