19.8 Common Mistakes: Storing contexts in Structs
Right, so you’ve heard the rule: “Don’t store context.Context in a struct.” You’ve probably nodded along, but let’s be honest, you’re also thinking, “But… why? It seems so convenient.” I get it. It feels like the perfect place to stash that cancellation signal so all your methods can use it. It’s a trap. Let’s break down exactly why this is the software equivalent of storing nitroglycerin in a shoebox—it might be fine until it isn’t, and when it goes wrong, it’s spectacular.