What Is a Type Switch in Go and When Should You Use It?
Type Switch is one of the best features in Go, and today we're going to take a look at it! To prepare for all the Go 1.27 changes, watch this video: https://youtu.be/RboN0J87NrA 📝 Description In this practical tutorial, we build a small JSON redaction function using Go’s type switch to automatically find and hide sensitive values in unknown JSON payloads. Here's what you will learn: • Why logging raw requests or webhook payloads can expose passwords, tokens, and API keys. • How to handle JSON with an unknown shape by decoding it into any. • How a type switch lets you inspect and process values by their actual runtime type. • How to recursively redact secrets nested inside objects and arrays. • How to detect common JWTs in strings and replace them safely. • Best practices for keeping your logs useful without storing sensitive credentials. ⏳ Timestamps: 00:00 - Introduction 00:25 - Use Case 12:16 - 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. 📨 Support and Connect! 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 was designed by Renée French (Source: https://go.dev/blog/gopher License details: https://creativecommons.org/licenses/by/4.0/). The gopher appearing in this video and thumbnail has been modified from the original design and is based on an illustration from Maria Letta's free-gophers-pack (Source: https://github.com/MariaLetta/free-gophers-pack License: CC0 1.0 Public Domain https://creativecommons.org/publicdomain/zero/1.0/). #go #type #switch




Join the discussion
Have something to add?
Sign in to reply, follow this thread, and earn XP when your answer helps someone.