context

package
v0.0.0-...-8b1022e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

README

context Travis CI Status Coverage Status

Provides goroutine-based context state inspired by https://github.com/tylerb/gls and https://github.com/jtolds/gls. It uses the same basic hack as tylerb's library, but adds a stack abstraction that allows nested contexts similar to jtolds' library, but using Enter() and Exit() instead of callback functions.

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.
	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
}

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 globalc context.
	PutGlobal(key string, value interface{})

	// PutGlobalDynamic puts a key->value pair into the global context wwhere the value is
	// generated by a function that gets evaluated at every Read.
	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
}

Manager provides the ability to create and access Contexts.

func NewManager

func NewManager() Manager

NewManager creates a new Manager

type Map

type Map map[string]interface{}

Map is a map of key->value pairs.

func (Map) Fill

func (_m Map) Fill(m Map)

Fill implements the method from the Contextual interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL