Last Updated: May 22, 2026
context.WithValue attaches request-scoped data to a context so it can travel through every function call in a request's lifecycle without being threaded as an explicit parameter. It fits trace IDs, user IDs, and request IDs that middleware needs to pass downstream, and it's the wrong choice for almost everything else. This lesson covers the mechanics, the custom-key pattern that prevents package collisions, and the rules for what belongs in a context value versus what should stay a regular function argument.