A Go Gotcha: Context Keys Are Typed 0 ▲ Henrique Dias 54 minutes ago · Tech · hide Today I want to describe a small bug I uncovered a few years ago at work. I was working on a naming system, akin to DNS, which allowed you to provide a TTL when publishing or updating a name. After some attempts at making the TTL larger, it always remained at 0. The flag wasn’t being honored! At this point, if you’re familiar with Go and read the title, you probably already know where this is going. Let’s start by saying that the CLI tool that received the option value and the library where all the naming magic happened are different packages, and this is how the CLI tool prepared the option to pass it down: type requestContextKey string ctx = context.WithValue(ctx, requestContextKey("ipns-publish-ttl"), *options.TTL) And then, this is how the library tried to read that option: var ttlContextKey contextKey = "ipns-publish-ttl" v := ctx.Value(ttlContextKey) d, ok := v.(time.Duration) Do you see the problem? I’m almost sure this is a common Go gotcha - ah! - and that’s probably why,… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town