plugin

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(pluginName string)

Main is a helper function that can be used to provide a consistent main func. Plugins aren't normally executed anyway, but Go requires that every "main" package have a "main" func.

Types

type Initializer

type Initializer interface {
	// Initialize creates the corresponding Plugin for this Initializer.
	Initialize(*Manager) (Plugin, error)
}

An Initializer is a type that can create a Plugin implementation.

func InitializeFromFile

func InitializeFromFile(p string) Initializer

InitializeFromFile returns an Initializer that will attempt to load the specified plugin shared library from the filesystem. Shared library plugins must be built as a `main` package and must have an "Initialize" function defined at the package level. The "Initialize" function must be compatible with the Initialize method on the Initializer interface. That is, it must have the signature:

func Initialize(*Manager) (Plugin, error)

type InitializerFunc

type InitializerFunc func(*Manager) (Plugin, error)

An InitializerFunc is a function that implements Initializer.

func (InitializerFunc) Initialize

func (f InitializerFunc) Initialize(m *Manager) (Plugin, error)

type Manager

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

A Manager controls the loading and configuration of plugins.

func NewManager

func NewManager(plugins ...string) *Manager

func (*Manager) Configure

func (m *Manager) Configure() []error

Configure attempts to load and configure all registered plugins. An error will be returned for each failed initialization.

func (*Manager) Loaded

func (m *Manager) Loaded() []string

Loaded returns a list of plugins currently loaded.

func (*Manager) Lookup

func (m *Manager) Lookup(name string) (Plugin, error)

Lookup returns the given plugin by name, or an error if it isn't loaded.

func (*Manager) OnPluginInit

func (m *Manager) OnPluginInit(h PluginInitHandler)

OnPluginInit adds the given PluginInitHandler to be called when a plugin is initialized.

func (*Manager) OnShutdown

func (m *Manager) OnShutdown(h ShutdownHandler)

OnShutdown adds the given ShutdownHandler to be called when the appliation is shutting down.

func (*Manager) Register

func (m *Manager) Register(initfn Initializer)

Register adds a plugin Initializer to the Manager. Invoke all the registered Initializers by calling Configure on the Manager.

func (*Manager) RegisterFunc

func (m *Manager) RegisterFunc(initfn func(m *Manager) (Plugin, error))

RegisterFunc is a shorthand method to register an InitializerFunc without extra type assertions.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown begins the shut down process. Each ShutdownHandler is called concurrently and this method returns after all handlers have completed.

type Plugin

type Plugin interface {
	// Name returns the unique name for the Plugin.
	Name() string
}

A Plugin is the basic interface that all squircy3 plugins must implement.

type PluginInitHandler added in v0.10.0

type PluginInitHandler interface {
	// HandlePluginInit is called after each other Plugin is initialized.
	// Plugin initialization occurs when the Configure method is called on
	// a plugin.Manager.
	HandlePluginInit(Plugin)
}

PluginInitHandler is implemented by types that want to be notified when another plugin is initialized.

type ShutdownHandler

type ShutdownHandler interface {
	// HandleShutdown is called when the application begins shutting down.
	// All ShutdownHandlers are invoked concurrently, but each has a limited
	// amount of time to gracefully clean up before the application forcefully
	// exits.
	HandleShutdown()
	Name() string
}

ShutdownHandler is implemented by types that want to perform some action when the application is shutting down.

Jump to

Keyboard shortcuts

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