Documentation
¶
Overview ¶
Package context provides a mechanism for transparently tracking contextual state associated to the current goroutine and even across goroutines.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context interface { // Enter enters a new level on this Context stack. Enter() Context // Go starts the given function on a new goroutine. Go(fn func()) // Exit exits the current level on this Context stack. Exit() // Put puts a key->value pair into the current level of the context stack. Put(key string, value interface{}) Context // PutIfAbsent puts the given key->value pair into the current level of the // context stack if and only if that key is defined nowhere within the context // stack (including parent contexts). PutIfAbsent(key string, value interface{}) Context // PutDynamic puts a key->value pair into the current level of the context // stack where the value is generated by a function that gets evaluated at // every Read. If the value is a map[string]interface{}, we will unpack the // map and set each contained key->value pair independently. PutDynamic(key string, valueFN func() interface{}) Context // Fill fills the given map with data from this Context Fill(m Map) // AsMap returns a map containing all values from the supplied obj if it is a // Contextual, plus any addition values from along the stack, plus globals if // so specified. AsMap(obj interface{}, includeGlobals bool) Map // Get gets the value at the given key, ascending through the context hierarchy // until it finds a value, or returning the global value if none found in contexts. Get(key string) (interface{}, bool) }
Context is a context containing key->value pairs
type Contextual ¶
type Contextual interface { // Fill fills the given Map with all of this Contextual's context Fill(m Map) }
Contextual is an interface for anything that maintains its own context.
type Manager ¶
type Manager interface { // Enter enters a new level on the current Context stack, creating a new Context // if necessary. Enter() Context // Go starts the given function on a new goroutine but sharing the context of // the current goroutine (if it has one). Go(func()) // PutGlobal puts the given key->value pair into the global context. PutGlobal(key string, value interface{}) // PutGlobalDynamic puts a key->value pair into the global context where the // value is generated by a function that gets evaluated at every Read. If the // value is a map[string]interface{}, we will unpack the map and set each // contained key->value pair independently. PutGlobalDynamic(key string, valueFN func() interface{}) // AsMap returns a map containing all values from the supplied obj if it is a // Contextual, plus any addition values from along the stack, plus globals if so // specified. AsMap(obj interface{}, includeGlobals bool) Map // Get gets the value at the given key from the current context, ascending through // the context hierarchy until it finds a value, or returning the global value if none // found in contexts. Get(key string) (interface{}, bool) }
Manager provides the ability to create and access Contexts.
Click to show internal directories.
Click to hide internal directories.