plugin

package
v0.0.0-...-3f1871c Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: MIT, MIT Imports: 5 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPluginNotFound = errors.New("vinxi: plugin does not exists")

ErrPluginNotFound is used when a plugin does not exists.

View Source
var Plugins = make(map[string]Info)

Plugins is used to store the available plugins globally.

Functions

func Exists

func Exists(name string) bool

Exists is used to check if a given plugin name exists.

func Register

func Register(plugin Info)

Register registers the given plugin in the current store.

func Validate

func Validate(params Params, opts config.Config) error

Validate is used to validates plugin params and report the proper param specific error.

Types

type Factory

type Factory func(config.Config) Handler

Factory represents the plugin factory function interface.

func GetFactory

func GetFactory(name string) Factory

GetFactory is used to find and retrieve a plugin factory function.

type Field

type Field struct {
	Name        string      `json:"name,omitempty"`
	Type        string      `json:"type,omitempty"`
	Description string      `json:"description,omitempty"`
	Mandatory   bool        `json:"mandatory,omitempty"`
	Examples    []string    `json:"examples,omitempty"`
	Default     interface{} `json:"default,omitempty"`
	Validator   Validator   `json:"-"`
}

Field is used to declare specific config fields supported by plugins.

type Handler

type Handler func(http.Handler) http.Handler

Handler represents the plugin specific HTTP handler function interface.

type Info

type Info struct {
	Name        string  `json:"name,omitempty"`
	Description string  `json:"description,omitempty"`
	Params      Params  `json:"params,omitempty"`
	Factory     Factory `json:"-"`
}

Info represents the plugin entity fields storing the name, description and factory function used to initialize the fields.

func GetInfo

func GetInfo(name string) Info

GetInfo is used to find and retrieve a plugin info struct, if exists.

type Layer

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

Layer represents a plugins layer designed to intrument proxies providing plugin based dynamic configuration capabilities, such as register/unregister or enable/disable plugins at runtime satefy.

func NewLayer

func NewLayer() *Layer

NewLayer creates a new plugins layer.

func (*Layer) All

func (l *Layer) All() []Plugin

All returns an slice of the registered plugins.

func (*Layer) Flush

func (l *Layer) Flush()

Flush removes all the registered plugins.

func (*Layer) Get

func (l *Layer) Get(name string) Plugin

Get finds and returns a plugin instance.

func (*Layer) HandleHTTP

func (l *Layer) HandleHTTP(w http.ResponseWriter, r *http.Request, h http.Handler)

HandleHTTP triggers the plugins layer call chain. This function is designed to be executed by top-level middleware layers.

func (*Layer) Len

func (l *Layer) Len() int

Len returns the registered plugins length.

func (*Layer) Remove

func (l *Layer) Remove(id string) bool

Remove removes a plugin looking by its unique identifier.

func (*Layer) Use

func (l *Layer) Use(plugin ...Plugin)

Use registers one or multiples plugins in the current plugin layer.

type NewFunc

type NewFunc func(config.Config) (Plugin, error)

NewFunc represents the Plugin constructor factory function interface.

func Get

func Get(name string) NewFunc

Get is used to find and retrieve a plugin.

func New

func New(info Info) NewFunc

New creates a new Plugin capable interface based on the given HTTP handler logic encapsulated as plugin.

type Params

type Params []Field

Params represents the list of supported config fields by plugins.

type Plugin

type Plugin interface {
	// ID is used to retrieve the plugin unique identifier.
	ID() string
	// Name is used to retrieve the plugin name identifier.
	Name() string
	// Description is used to retrieve a human friendly
	// description of what the plugin does.
	Description() string
	// Config is used to retrieve the user defined plugin config.
	Config() config.Config
	// Metadata is used to retrieve the plugin metadata.
	Metadata() config.Config
	// HandleHTTP is used to run the plugin task.
	// Note: add error reporting layer.
	HandleHTTP(http.Handler) http.Handler
}

Plugin represents the required interface implemented by plugins.

func Init

func Init(name string, opts config.Config) (Plugin, error)

Init is used to initialize a new plugin by name identifier based on the given config options.

func NewWithConfig

func NewWithConfig(info Info, opts config.Config) (Plugin, error)

NewWithConfig creates a new Plugin capable interface based on the given HTTP handler logic encapsulated as plugin.

type Validator

type Validator func(interface{}, config.Config) error

Validator represents the plugin config field validator function interface.

Jump to

Keyboard shortcuts

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