You are providing fallback values in Golang wrong!

Опубликовано: 25 Май 2026
на канале: Flo Woelki
7,100
335

Golang 1.22 has a brand new feature, the cmp.Or function. If you want to know everything about structs, I highly recommend watching this video:    • This is your last video about Golang Structs!  .


📝 Description
In this video, we delve into the power and versatility of the `cmp.Or` function in Golang. This function, a part of the `cmp` package, allows us to streamline our code and make it more readable and efficient. We start by discussing the general functionality of the `cmp.Or` function, including its ability to return the first non-zero value from a list of arguments. Then, we walk you through several practical use cases, such as configuring a web server's port, handling optional user input in a chatroom, and optimizing sorting of a slice of structs.


⏳ Timestamps:
00:00 - Introduction
00:31 - What is the cmp.Or function
01:50 - 1. Use Case: Fallback Values
05:23 - 2. Use Case: More Fallback Values
08:18 - 3. Use Case: Sorting
12:45 - 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!
Become a member.    / @flowoelki  
Discord:   / discord  
X / Twitter: https://x.com/FlorianWoelki
LinkedIn:   / florian-woelki  
GitHub: https://github.com/FlorianWoelki


📝 Copyright Notice
The original Go Gopher was designed by Renée French (Source: https://go.dev/blog/gopher License details: https://creativecommons.org/licenses/.... The gopher appearing in this video and thumbnail is modified from the original design.


#golang #go #golang1.22