context

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthToken

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

AuthToken returns the context's security token. This value is valid on both the client and the server.

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 MustAuthToken

func MustAuthToken(ctx context.Context) *types.AuthToken

MustAuthToken returns the context's security token and panics if it does not exist and/or cannot be type cast.

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 MustDriver

func MustDriver(ctx context.Context) types.StorageDriver

MustDriver returns the context's storage driver or panics if no driver exists.

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 MustPathConfig

func MustPathConfig(ctx context.Context) *types.PathConfig

MustPathConfig returns the context's path config 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 MustSession

func MustSession(ctx context.Context) interface{}

MustSession returns the context's session object and panics if a session does not exist.

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

func New(parent context.Context) types.Context

New returns a new context with the provided parent.

func PathConfig

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

PathConfig returns the context's path config. This value is valid on both the client and the server.

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 RegisterCustomKeyWithContext

func RegisterCustomKeyWithContext(
	ctx types.Context, key interface{}, mask CustomKeyTypes) error

RegisterCustomKeyWithContext 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 Session

func Session(ctx context.Context) (interface{}, bool)

Session returns the context's session object. This value is valid only on the server.

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 WithCancel

func WithCancel(parent context.Context) (types.Context, context.CancelFunc)

WithCancel returns a copy of parent with a new Done channel. The returned context's Done channel is closed when the returned cancel function is called or when the parent context's Done channel is closed, whichever happens first.

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 WithStorageSession

func WithStorageSession(parent context.Context) (types.Context, error)

WithStorageSession returns a context that is logged into the storage platform.

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 (

	// PathConfigKey is a context key.
	PathConfigKey Key

	// LoggerKey is a context key.
	LoggerKey

	// 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

	// SessionKey is the key for the storage driver's session.
	SessionKey

	// EncodedAuthTokenKey is the key for an encoded authentication token.
	EncodedAuthTokenKey

	// AuthTokenKey is a context key.
	AuthTokenKey

	// 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