๐ Inspect private context.Context internals
You can fetch this library by running the following
go get -u github.com/joshdk/contents
import (
"context"
"fmt"
"github.com/joshdk/contents"
)
// Build a context
ctx := context.Background()
ctx = context.WithValue(ctx, "key-1", "val-1")
ctx = context.WithValue(ctx, "key-2", "val-2")
ctx = context.WithValue(ctx, "key-3", "val-3")
// Extract list of all keys
keys := contents.Keys(ctx)
for _, key := range keys {
fmt.Printf("Context contains %q โ %q\n", key, ctx.Value(key))
// Context contains "key-1" โ "val-1"
// Context contains "key-2" โ "val-2"
// Context contains "key-3" โ "val-3"
}
This library is distributed under the MIT License, see LICENSE.txt for more information.