10 Go Conventions That Clicked Too Late for an AI Engineer

· Towards Dev ·

1 min read Original article ↗

The ones that only make sense after you’ve been burned by them

Cheikh seck

I spent three years writing Go for inference gateways before I realized I was fighting the language instead of using it.

I’d write a handler, ship it, and six months later someone would point out that I’d used context wrong, or that my error wrapping was leaking, or that my goroutine was going to take down the pod. Each time I'd think: why didn't anyone tell me this in week one?

These aren’t rules you learn in a tutorial. They’re conventions that only click when you’ve been burned by their absence. Here are the ten that hit me hardest.

Press enter or click to view image in full size

1. context Is Not a Request Bag — It's a Cancellation Contract

Everyone’s first instinct is to stuff values into context.WithValue. I did this for two years. Then a timeout propagated through my gateway and took down a model swap because the value was still there.

The convention that clicked: context is for cancellation, deadlines, and tracing — not for passing data your handler needs.

// WRONG: stuff the user ID in context
func handler(ctx context.Context) {
userID, _ := ctx.Value("user_id").(string)
}

// RIGHT…