decorator

package
v2.0.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2015 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecorateRegistry

func DecorateRegistry(registry storage.Registry, decorator Decorator) storage.Registry

DecorateRegistry the provided registry with decorator. Registries may be decorated multiple times.

Types

type Decorator

type Decorator interface {
	Decorate(v interface{}) interface{}
}

Decorator provides an interface for intercepting object creation within a registry. The single method accepts an registry storage object, such as a Layer, optionally replacing it upon with an alternative object or a wrapper.

For example, if one wants to intercept the instantiation of a layer, an implementation might be as follows:

func (md *DecoratorImplementation) Decorate(v interface{}) interface{} {
	switch v := v.(type) {
	case Layer:
		return wrapLayer(v)
	}

	// Make sure to return the object or nil if the decorator doesn't require
	// replacement.
	return v
}

Such a decorator can be used to intercept calls to support implementing complex features outside of the storage package.

type Func

type Func func(v interface{}) interface{}

Func provides a shortcut handler for decorators that only need a function. Use is similar to http.HandlerFunc.

func (Func) Decorate

func (df Func) Decorate(v interface{}) interface{}

Decorate allows DecoratorFunc to implement the Decorator interface.

Jump to

Keyboard shortcuts

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