middlewares

package
v0.0.0-...-5c5b187 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRegistry = New()

DefaultRegistry - Default global registry.

Functions

func Alias

func Alias(source, dest string, def *Middleware)

Alias - Registers a middleware alias with overwritten options defaults.

func Construct

func Construct(m *Middleware) (func(next xhandler.HandlerC) xhandler.HandlerC, error)

Construct - Constructs middleware handler from name and options.

func Exists

func Exists(name string) bool

Exists - Checks if middleware with given name exists in registry.

func HasBreak

func HasBreak(ctx context.Context) bool

HasBreak - Returns true if break was set in given context.

func Register

func Register(desc Descriptor, constructor Constructor)

Register - Registers a middleware constructor function. Panics if descriptor name is empty.

func WithBreak

func WithBreak(ctx context.Context) context.Context

WithBreak - Returns new context with a break for consideration for next middlewares

Types

type Constructor

type Constructor func(Options) (Handler, error)

Constructor - Middleware constructor.

type Descriptor

type Descriptor struct {
	// Name - Middleware name.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// Description - Middleware description.
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	// Options - Options descriptors.
	Options []*options.Option `json:"options,omitempty" yaml:"options,omitempty"`
}

Descriptor - Web route middleware descriptor. Describes functionality of middleware and its options.

func DescriptorByName

func DescriptorByName(name string) (Descriptor, bool)

DescriptorByName - Returns middleware descriptor by name.

func Descriptors

func Descriptors() (desc []Descriptor)

Descriptors - Returns all registered middlewares descriptors.

type Handler

type Handler func(next xhandler.HandlerC) xhandler.HandlerC

Handler - Middleware http handler.

func ToHandler

func ToHandler(fn func(ctx context.Context, w http.ResponseWriter, r *http.Request, next xhandler.HandlerC)) Handler

ToHandler - Converts function to middleware.

type Middleware

type Middleware struct {
	// Name - Name of middleware to construct.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// Options - Options used to construct middleware.
	Options template.Context `json:"options,omitempty" yaml:"options,omitempty"`
	// Context - Like options but values are context keys.
	Context template.Context `json:"context,omitempty" yaml:"context,omitempty"`
	// Template - Like options but values are templates.
	Template template.Context `json:"template,omitempty" yaml:"template,omitempty"`
}

Middleware - Web route middleware. Name is a name of globally registered middleware. Its used to construct middlewares from config file.

func (*Middleware) ConstructOptions

func (middleware *Middleware) ConstructOptions() (_ Options, err error)

ConstructOptions - Creates middleware options.

func (*Middleware) SetDefaults

func (middleware *Middleware) SetDefaults(other *Middleware)

SetDefaults - Set options defaults.

func (*Middleware) Validate

func (middleware *Middleware) Validate(opts []*options.Option) error

Validate - Validates if options have proper types and if all required are not empty.

type Options

type Options interface {
	// Int - Gets option int value.
	Int(context.Context, *options.Option) (int, error)

	// Bool - Gets option bool value.
	Bool(context.Context, *options.Option) (bool, error)

	// String - Gets option string value.
	String(context.Context, *options.Option) (string, error)

	// Duration - Gets duration value.
	Duration(context.Context, *options.Option) (time.Duration, error)

	// Map - Gets option map value.
	Map(context.Context, *options.Option) (template.Context, error)

	// List - Gets option list value.
	List(context.Context, *options.Option) ([]interface{}, error)

	// StringList - Gets option strings list value.
	StringList(context.Context, *options.Option) ([]string, error)
}

Options - Web route middleware constructor options interface.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry - Middlewares registry.

func New

func New() *Registry

New - Constructs new middlewares registry.

func (*Registry) Alias

func (registry *Registry) Alias(source, dest string, def *Middleware)

Alias - Registers a middleware alias with overwritten options defaults.

func (*Registry) Construct

func (registry *Registry) Construct(m *Middleware) (Handler, error)

Construct - Constructs middleware handler from name and options.

func (*Registry) DescriptorByName

func (registry *Registry) DescriptorByName(name string) (_ Descriptor, _ bool)

DescriptorByName - Returns middleware descriptor by name.

func (*Registry) Descriptors

func (registry *Registry) Descriptors() (desc []Descriptor)

Descriptors - Returns all registered middlewares descriptors.

func (*Registry) Exists

func (registry *Registry) Exists(name string) bool

Exists - Checks if middleware with given name exists in registry.

func (*Registry) Register

func (registry *Registry) Register(desc Descriptor, constructor Constructor)

Register - Registers a middleware constructor function. Panics if descriptor name is empty.

Jump to

Keyboard shortcuts

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