Documentation ¶
Index ¶
- func MustTypeOfInterface(iface any) reflect.Type
- func TypeOfInterface(iface any) (reflect.Type, error)
- type Plugin
- type PluginInfo
- type Registry
- func (r *Registry) MustRegister(p Plugin)
- func (r *Registry) PluginByName(name string) (PluginInfo, bool)
- func (r *Registry) PluginNames() []string
- func (r *Registry) Plugins() []PluginInfo
- func (r *Registry) PluginsImplementing(iface any) ([]PluginInfo, error)
- func (r *Registry) Register(p Plugin) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustTypeOfInterface ¶
MustTypeOfInterface wraps TypeOfInterface, converting all errors to panics.
func TypeOfInterface ¶
TypeOfInterface returns the reflection type representing the dynamic type of iface. Construct a nil value via (*Iface)(nil).
Values of reflect.Type are used directly.
Logically this function is equivalent to the following:
reflect.TypeOf((*Iface)(nil)).Elem()
Types ¶
type Plugin ¶
type Plugin interface {
PluginInfo() PluginInfo
}
Plugin is the interface shared by all plugin implementations. Most plugins will implement additional interfaces for specific functionality.
type PluginInfo ¶
type PluginInfo struct { // Plugin name. Must not be empty. Name string // Sorting prioritiy. Within the same priority plugins are sorted by name. Priority int // New returns a new instance of the plugin. New func() (Plugin, error) }
PluginInfo represents a registered plugin.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) MustRegister ¶
MustRegister registers a plugin by receiving a plain and empty value of the plugin, i.e. without full initialization. In most cases the plugin package should invoke this function in its "init" function.
func init() { registry.MustRegister(&myPlugin{}) }
func (*Registry) PluginByName ¶
func (r *Registry) PluginByName(name string) (PluginInfo, bool)
PluginByName returns a plugin by its name.
func (*Registry) PluginNames ¶
PluginNames returns the names of all registered plugins.
func (*Registry) Plugins ¶
func (r *Registry) Plugins() []PluginInfo
Plugins returns all registered plugins.
func (*Registry) PluginsImplementing ¶
func (r *Registry) PluginsImplementing(iface any) ([]PluginInfo, error)
PluginsImplementing returns all plugins implementing a particular interface type. TypeOfInterface is used to determine the interface reflection type of the interface type.