Using context as a Key/Value Store

Let’s learn about passing values in a context and using it as a key/value store.

Passing values in a context

In this lesson, we pass values in a Context and use it as a key-value store. In this case, we do not pass values into contexts in order to provide further information about why they were canceled. The keyVal.go program illustrates the use of the context.TODO() function, as well as the use of the context.WithValue() function.

Coding example

All these and many more are found in keyVal.go, which is as follows:

Get hands-on with 1200+ tech skills courses.