plugin

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package plugin provides tools for loading and registering plugins

SPDX-License-Identifier: Apache-2.0

SPDX-License-Identifier: Apache-2.0

Index

Examples

Constants

View Source
const REGISTRABLE_VAR = "Registrable"

REGISTRABLE_VAR is the name to lookup after loading the plugin for the module registering

Variables

This section is empty.

Functions

func Load added in v1.4.0

func Load(cfg config.Plugin, reg *Register) (int, error)

Load loads all the plugins in pluginFolder with pattern in its filename. It returns the number of plugins loaded and an error if something goes wrong.

func Scan

func Scan(folder, pattern string) ([]string, error)

Types

type Plugin added in v1.4.0

type Plugin interface {
	Lookup(name string) (plugin.Symbol, error)
}

Plugin is the interface of the loaded plugins

type Register added in v1.4.0

type Register struct {
	Decoder  *encoding.DecoderRegister
	SD       *sd.Register
	External *register.Namespaced
}

Register contains all the registers required by the framework and the external modules

func NewRegister added in v1.4.0

func NewRegister() *Register

NewRegister returns a new register to be used by the plugin loader

func (*Register) Register added in v1.4.0

func (r *Register) Register(p Plugin) error

Register registers the received plugin in the proper internal registers

Example (Ok)
reg := NewRegister()
p := dummyPlugin{
	content: plugin.Symbol(registrableDummy(1)),
}
if err := reg.Register(p); err != nil {
	fmt.Println(err.Error())
}
Output:

registrable 1 from plugin samplePluginName is registering its decoder components
registrable 1 from plugin samplePluginName is registering its components depending on external modules
Example (UnknownInterface)
reg := NewRegister()
p := dummyPlugin{
	content: plugin.Symbol(1),
}
if err := reg.Register(p); err != nil {
	fmt.Println(err.Error())
}
Output:

unknown registrable interface

type RegistrableDecoder added in v1.4.0

type RegistrableDecoder interface {
	RegisterDecoder(func(name string, dec func(bool) func(io.Reader, *map[string]interface{}) error) error) error
}

RegistrableDecoder defines the interface the encoding plugins should implement in order to be able to register themselves

type RegistrableExternal added in v1.4.0

type RegistrableExternal interface {
	RegisterExternal(func(namespace, name string, v interface{})) error
}

RegistrableExternal defines the interface the external plugins should implement in order to be able to register themselves

Directories

Path Synopsis
tests
app
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0
plugins
SPDX-License-Identifier: Apache-2.0
SPDX-License-Identifier: Apache-2.0

Jump to

Keyboard shortcuts

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