Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMissingSymbolError ¶
IsMissingSymbolError tests err to see if it is a *MissingSymbolError. This function is a shorthand for situations where calling code only needs to be aware that an error indicated a symbol was missing.
Types ¶
type Annotated ¶
type Annotated struct {
// Name is the optional name of the component emitted by the Constructor.lue
// Either Name or Group must be set, or an error is raised.
Name string
// Group is the value group for the component emitted by the Constructor.
// Either Name or Group must be set, or an error is raised.
Group string
// Target is the name of a function symbol that must be legal to
// use with fx.Annotated.Target.
Target string
}
Annotated is an analog of fx.Annotated for plugin symbols. This type gives more control over how a plugin constructor gets placed into the enclosing fx.App.
type InvalidLifecycleError ¶
InvalidLifecycleError indicates that a symbol was not usable as an uber/fx lifecycle callback via fx.Hook.
func (*InvalidLifecycleError) Error ¶
func (ile *InvalidLifecycleError) Error() string
type InvalidTargetError ¶
InvalidTargetError indicates that a type was not valid for the fx.Annotated.Target field. This is more restrictive than a constructor. Targets must return exactly (1) non-error object, with an optional error.
func (*InvalidTargetError) Error ¶
func (ite *InvalidTargetError) Error() string
type Lifecycle ¶
type Lifecycle struct {
// OnStart is the optional symbol name of a function that can be invoked on application startup.
//
// This field must refer to an exported function in the plugin that has any of the following
// signatures:
//
// - func()
// - func() error
// - func(context.Context)
// - func(context.Context) error
//
// A function with any of those signatures will be registered as an fx.Hook and will run
// on application startup. Any other signature or non-function type will shortcircuit
// the application with an error.
OnStart string
// OnStop is the optional symbol name of a function that can be invoked on application shutdown.
// The symbol referred to by this field may have any of the same function signatures as OnStart.
OnStop string
// IgnoreMissing defines what happens when either OnStart or OnStop are set and not present.
// If this field is true, a missing OnStart or OnStop is silently ignored. If this field is false,
// then a missing OnStart or OnStop from a plugin will shortcircuit application startup with an error.
IgnoreMissing bool
}
Lifecycle describes how to bind a plugin to an enclosing application's lifecycle.
type MissingSymbolError ¶
MissingSymbolError indicates that a symbol was not found. This error is returned by Lookup to normalize errors coming from plugins.
func (*MissingSymbolError) Error ¶
func (mse *MissingSymbolError) Error() string
func (*MissingSymbolError) Unwrap ¶
func (mse *MissingSymbolError) Unwrap() error
type OpenError ¶
OpenError is returned by Open to indicate that a source of symbols could not be loaded.
type P ¶
type P struct {
// Name is the optional name of the plugin component within the application. This
// field is ignored if Anonymous is set.
Name string
// Group is the optional value group to place the loaded plugin into. This field
// is ignored if Anonymous is set.
Group string
// Anonymous controls whether the plugin itself is provided as a component
// to the enclosing fx.App. If this field is true, then the plugin is not
// placed into the fx.App regardless of the values of Name and Group.
Anonymous bool
// Path is the plugin's path. This field is required. Variables are expanded
// via os.ExpandEnv.
Path string
// Symbols describes the optional set of functions exported by the plugin to be
// bound to the enclosing fx.App. Both provide and invoke functions can be defined
// using this field.
Symbols Symbols
// Lifecycle is the optional binding from a plugin's symbols to the enclosing
// application.
Lifecycle Lifecycle
}
P describes how to load a single plugin and integrate it into an enclosing fx.App.
func (P) Provide ¶
Provide builds the appropriate options to integrate this plugin into an enclosing fx.App.
Typical usage:
app := fx.New(
pluginx.P{
Anonymous: true, // leave unset if you want the plugin accessible via DI
Path: "/etc/lib/something.so",
Symbols: pluginfx.Symbols {
Names: []interface{}{
"MyConstructor",
},
},
Lifecycle: pluginfx.Lifecycle {
OnStart: "Initialize",
},
}.Provide()
)
type Plugin ¶
type Plugin interface {
// Lookup returns the value of the given symbol, or an error
// if no such symbol exists.
//
// The *plugin.Plugin type returns a generated error from this method,
// making error disambiguation hard or impossible. The Lookup function
// in this package helps with that by ensuring that a *MissingSymbolError
// is returned in cases where a symbol cannot be found.
Lookup(string) (plugin.Symbol, error)
}
Plugin defines the behavior of something that can look up exported symbols. *plugin.Plugin implements this interface.
type S ¶
type S struct {
// Group is the optional value group to place each plugin in this set into. If this
// field is unset, the loaded plugins are not added as components.
Group string
// Paths are the plugin paths to load. Each of these paths may be a filesystem glob,
// in which case all matching files are loaded as plugins. Variable expansion is also
// done on each element via os.ExpandEnv.
Paths []string
// Symbols are the symbols to be loaded from each loaded plugin.
Symbols Symbols
// Lifecycle describes the symbols from each loaded plugin to be bound to the
// enclosing application.
Lifecycle Lifecycle
}
S describes how to load multiple plugins as a bundle and integrate each of them into an enclosing fx.App.
type SymbolMap ¶
type SymbolMap struct {
// contains filtered or unexported fields
}
SymbolMap is a map implementation of Symbols. It allows for an in-memory implementation of a plugin for testing or for production defaults.
The zero value of this type is a usable, empty "plugin". An existing map may be copied into a new *SymbolMap by using NewSymbolMap.
func NewSymbolMap ¶
NewSymbolMap shallow copies the contents of a map onto a new SymbolMap instance. Each symbol value is handled with Set.
func NewSymbols ¶
func NewSymbols(namesAndValues ...interface{}) *SymbolMap
NewSymbols is like NewSymbolMap, but it uses a sequence of name/value pairs. This function is often easier to use than NewSymbolMap, due to the noisiness of declaring a map.
This function panics if namesAndValues is not empty and does not have an even number of elements. It also panics if any even-numbered element (including zero) is not a string.
type Symbols ¶
type Symbols struct {
// Names are the symbol names to load into the enclosing fx.App. Each
// element of this slice must be either a string or an Annotated.
//
// Each symbol must refer to a function, or an error is raised.
//
// If an element is a string, it may be either a constructor or an invoke function.
// If the function returns nothing or an error, it is wrapped in fx.Invoke. Otherwise,
// it is passed to fx.Provide.
//
// If an element is an Annotated, then the Target field is used to load a constructor.
// This target constructor must return exactly (1) non-error value along with an optional
// error.
Names []interface{}
// IgnoreMissing controls what happens when a symbol is not found in a plugin.
// If this field is true, then missing symbols are silently ignored. Otherwise,
// a missing symbol will shortcircuit application startup with an error.
IgnoreMissing bool
}
Symbols describes how to bootstrap a set of symbols within an enclosing fx.App.