Documentation
¶
Index ¶
- Variables
- func Alias(source, dest string, def *Middleware)
- func Construct(m *Middleware) (func(next xhandler.HandlerC) xhandler.HandlerC, error)
- func Exists(name string) bool
- func HasBreak(ctx context.Context) bool
- func Register(desc Descriptor, constructor Constructor)
- func WithBreak(ctx context.Context) context.Context
- type Constructor
- type Descriptor
- type Handler
- type Middleware
- type Options
- type Registry
- func (registry *Registry) Alias(source, dest string, def *Middleware)
- func (registry *Registry) Construct(m *Middleware) (Handler, error)
- func (registry *Registry) DescriptorByName(name string) (_ Descriptor, _ bool)
- func (registry *Registry) Descriptors() (desc []Descriptor)
- func (registry *Registry) Exists(name string) bool
- func (registry *Registry) Register(desc Descriptor, constructor Constructor)
Constants ¶
This section is empty.
Variables ¶
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 Register ¶
func Register(desc Descriptor, constructor Constructor)
Register - Registers a middleware constructor function. Panics if descriptor name is empty.
Types ¶
type Constructor ¶
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 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.
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 (*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) Register ¶
func (registry *Registry) Register(desc Descriptor, constructor Constructor)
Register - Registers a middleware constructor function. Panics if descriptor name is empty.