June 2017
Intermediate to advanced
400 pages
10h 32m
English
When working with context values, it's good to create a new type to represent the key. In this case, we created a key type, then declared some corresponding const values to represent all of our possible keys.
In this case, we initialize all our key/value pairs at the same time using the Setup() function. When modifying contexts, functions generally take a context argument and return a context value. So the signature often looks like this:
func ModifyContext(ctx context.Context) context.Context
Sometimes, these methods also return an error or cancel() function, such as in the cases of context.WithCancel, context.WithTimeout, and context.WithDeadline. All child contexts inherit the attributes of the parent. In this recipe, ...
Read now
Unlock full access