context

package
v0.1.5-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2016 License: Apache-2.0 Imports: 11 Imported by: 97

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Background

func Background() types.Context

Background returns a new context with logging capabilities.

func Client

func Client(ctx context.Context) (types.Client, bool)

Client returns the context's Client. This value is only valid for contexts created on the client.

func CustomHeaderKeys

func CustomHeaderKeys() <-chan interface{}

CustomHeaderKeys returns a channel on which can be received all the registered, custom header keys.

func CustomLoggerKeys

func CustomLoggerKeys() <-chan interface{}

CustomLoggerKeys returns a channel on which can be received all the registered, custom logger keys.

func Driver

func Driver(ctx context.Context) (types.StorageDriver, bool)

Driver returns the context's storage driver. This value is valid only on the server and subject to the same restrictions as listed in the Service function.

func GetLogLevel

func GetLogLevel(ctx context.Context) (log.Level, bool)

GetLogLevel gets the context's log level.

func InstanceID

func InstanceID(ctx context.Context) (*types.InstanceID, bool)

InstanceID returns the context's InstanceID. This value is valid on both the client and the server.

func Join

func Join(left types.Context, right context.Context) types.Context

Join joins this context with another, such that value lookups will first first check the current context, and if no such value exist, a lookup will be performed against the right side.

func LocalDevices

func LocalDevices(ctx context.Context) (*types.LocalDevices, bool)

LocalDevices returns the context's local devices map. This value is valid on both the client and the server.

func MustClient

func MustClient(ctx context.Context) types.Client

MustClient returns the context's Client and panics if the client is not available and/or not castable..

func MustInstanceID

func MustInstanceID(ctx context.Context) *types.InstanceID

MustInstanceID returns the context's InstanceID and panics if it does not exist and/or cannot be type cast.

func MustService

func MustService(ctx context.Context) types.StorageService

MustService returns the context's StorageService and panics if it does not exist and/or cannot be type cast.

func MustTransaction

func MustTransaction(ctx context.Context) *types.Transaction

MustTransaction returns the context's Transaction and will panic if the value is missing or not castable.

func New added in v0.1.1

func New(parent context.Context) types.Context

New returns a new context with the provided parent.

func Profile

func Profile(ctx context.Context) (string, bool)

Profile returns the context's profile. This value is only valid for contexts created on the server after the profile handler has been executred.

func RegisterCustomKey

func RegisterCustomKey(key interface{}, mask CustomKeyTypes) error

RegisterCustomKey registers a custom key with the context package.

func RequireTX

func RequireTX(ctx context.Context) types.Context

RequireTX ensures a context has a transaction, and if it doesn't creates a new one.

func Route

func Route(ctx context.Context) (types.Route, bool)

Route returns the context's route. This value is only valid for contexts created on the server after a mux has received an incoming HTTP request. Any part of the libStorage workflow after that, including the handlers, routers, and storage drivers, should have access to the Route.

func Server

func Server(ctx context.Context) (string, bool)

Server returns the context's server name. This value is valid on both the client and the server.

func Service

func Service(ctx context.Context) (types.StorageService, bool)

Service returns the context's storage service. This value is valid only for contexts created on the server. The value is only available after the service has been injected as part of the ServiceValidator handler or by one of the routes that injects it manually such as Volumes or Snapshots.

func ServiceName

func ServiceName(ctx context.Context) (string, bool)

ServiceName returns the context's service name. This value is valid for contexts created on both the client and the server. On the server this value is subject to the same restrictions as listed in the Service function.

func SetLogLevel

func SetLogLevel(ctx context.Context, lvl log.Level)

SetLogLevel sets the context's log level.

func Transaction

func Transaction(ctx context.Context) (*types.Transaction, bool)

Transaction returns the context's Transaction. This value is valid on both the client and the server.

func Value

func Value(ctx context.Context, key interface{}) interface{}

Value returns the value associated with this context for key, or nil if no value is associated with key. Successive calls to Value with the same key returns the same result.

func WithRequestRoute

func WithRequestRoute(
	parent context.Context,
	req *http.Request,
	route types.Route) types.Context

WithRequestRoute returns a new context with the injected *http.Request and Route.

func WithStorageService

func WithStorageService(
	parent context.Context, service types.StorageService) types.Context

WithStorageService returns a new context with the StorageService as the value and attempts to assign the service's associated InstanceID and LocalDevices (by way of the service's StorageDriver) to the context as well.

func WithValue

func WithValue(ctx context.Context, key, val interface{}) types.Context

WithValue returns a copy of parent in which the value associated with key is val.

Types

type CustomKeyTypes

type CustomKeyTypes int

CustomKeyTypes is a bitmask used when registering a custom key with the context at runtime.

const (
	// CustomLoggerKey indicates a value set for this key should be logged as
	// a member of a log entry's fields collection when using the context's
	// structured logger.
	CustomLoggerKey CustomKeyTypes = 1 << iota

	// CustomHeaderKey indicates a value set for this key should be sent along
	// with HTTP requests as an HTTP header.
	CustomHeaderKey
)

type Key

type Key int

Key is the type used as a context key.

const (

	// LoggerKey is a context key.
	LoggerKey Key

	// HTTPRequestKey is a context key.
	HTTPRequestKey

	// AllInstanceIDsKey is the key for the map[string]*types.InstanceID value
	// that maps all drivers to their instance IDs.
	AllInstanceIDsKey

	// LocalDevicesKey is a context key.
	LocalDevicesKey

	// AllLocalDevicesKey is the key for the map[string]*types.LocalDevices
	// value that maps all drivers to their instance IDs.
	AllLocalDevicesKey

	// AdminTokenKey is the key for the server's admin token.
	AdminTokenKey

	// ClientKey is a context key.
	ClientKey

	// TaskKey is a context key.
	TaskKey

	// InstanceIDKey is a context key.
	InstanceIDKey

	// ProfileKey is a context key.
	ProfileKey

	// RouteKey is a context key.
	RouteKey

	// ServerKey is a context key.
	ServerKey

	// ServiceKey is an alias for StorageService.
	ServiceKey

	// StorageServiceKey is a context key.
	StorageServiceKey

	// TransactionKey is a context key.
	TransactionKey

	// DriverKey is an alias for StorageDriver.
	DriverKey

	// UserKey is a context key.
	UserKey

	// HostKey is a context key.
	HostKey

	// TLSKey is a context key.
	TLSKey
)

func (Key) String

func (k Key) String() string

String returns the name of the context key.

Jump to

Keyboard shortcuts

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