plugin

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 5 Imported by: 0

README

go-plugin

GoDoc Travis Coveralls

go-plugin is a wrapper around go-resolve which makes it easy to load plugins that depend on each other based on a whitelist and blacklist.

Types of Plugins

There are two types of plugins. Providers and Optional plugins.

Providers are always loaded by the system, regardless of the whitelist/blacklist. They can still take arguments, even from optional plugins.

Optional plugins are loaded based on the whitelist/blacklist.

Plugin Requirements

Each plugin needs to be a function which runs the code to load that plugin. Any type in the method signature will be handled using injection. Any returned error will halt plugin loading and return that error from Registry.Load.

Important Dependencies

go-resolve does most of the heavy lifting by running a topological sort of all the plugins so they're loaded in the proper order. It relies on inject to do the reflection work to actually load the plugins.

glob is used in the whitelist and blacklist to determine which plugins should be loaded. There are a few tricks with the glob syntax, so be sure to look here if you're having trouble.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ensure

func Ensure(err error)

Ensure is a simple wrapper which will panic if the given error is non-nil.

Types

type Registry

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

Registry represents a group of plugins which can be loaded. This is mostly a wrapper for go-resolve, so the same semantics apply

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new empty Registry.

func (*Registry) Copy

func (r *Registry) Copy() *Registry

Copy creates a new instance of the registry which can be modified without changing the base. The general use case for this is instances where you want a global registry of plugins, but want to add separate providers for each instance of something, such as a bot.

func (*Registry) Load

func (r *Registry) Load(whitelist, blacklist []string) (inject.Injector, error)

Load takes a whitelist and a blacklist in glob form and returns an inject.Injector representing the loaded plugins or an error representing why the loading failed.

func (*Registry) Register

func (r *Registry) Register(name string, factory interface{}) error

Register simply ensures the provided factory is valid and adds the factory to a mapping under the given plugin name.

func (*Registry) RegisterProvider

func (r *Registry) RegisterProvider(name string, factory interface{}) error

RegisterProvider registers a factory as a part of the framework, so it will always be loaded.

Jump to

Keyboard shortcuts

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