Documentation
¶
Index ¶
- func EachSymbol(s Symbols, sv SymbolVisitor, names ...string) error
- func Lookup(s Symbols, name string) (interface{}, error)
- func LookupConstructor(s Symbols, name string) (reflect.Value, error)
- func LookupLifecycle(s Symbols, name string) (func(context.Context) error, error)
- type InvalidConstructorError
- type InvalidLifecycleError
- type MissingSymbolError
- type Plugin
- type Set
- type SymbolMap
- type SymbolVisitor
- type Symbols
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EachSymbol ¶ added in v0.0.1
func EachSymbol(s Symbols, sv SymbolVisitor, names ...string) error
EachSymbol applies a visitor over a set of symbols.
func LookupConstructor ¶ added in v0.0.1
Types ¶
type InvalidConstructorError ¶ added in v0.0.1
InvalidConstructorError indicates that a symbol was not usable as an uber/fx constructor.
func (*InvalidConstructorError) Error ¶ added in v0.0.1
func (ice *InvalidConstructorError) Error() string
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 MissingSymbolError ¶
MissingSymbolError indicates that a symbol was not found.
*plugin.Plugin does not return this error. It returns a generated using fmt.Errorf. This package's code normalizes these errors to errors of this type.
func (*MissingSymbolError) Error ¶
func (mse *MissingSymbolError) Error() string
func (*MissingSymbolError) Unwrap ¶
func (mse *MissingSymbolError) Unwrap() error
type Plugin ¶
type Plugin 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. Path string // IgnoreMissingConstructors controls what happens if a symbol in the Constructors // field is not present in the plugin. If this field is true, missing constructor // symbols are silently ignored. Otherwise, missing constructor symbols will shortcircuit // application startup with one or more errors. IgnoreMissingConstructors bool // Constructors are the optional exported functions from the plugin that participate // in dependency injection. Each constructor is passed to fx.Provide. Constructors []string // IgnoreMissingLifecycle controls what happens if OnStart or OnStop are not symbols // in the plugin. If this field is true and either OnStart or OnStop are not present, // no error is raised. Otherwise, application startup is shortcircuited with one or // more errors. IgnoreMissingLifecycle bool // OnStart is the optional exported function that should be called when the enclosing // application is started. OnStart string // OnStop is the optional exported function that should be called when the enclosing // application is stopped. OnStop string }
Plugin describes how to load a single plugin and integrate it into an enclosing fx.App.
func (Plugin) Provide ¶ added in v0.0.1
Provide builds the appropriate options to integrate this plugin into an enclosing fx.App.
Typical usage:
app := fx.New( pluginx.Plugin{ Path: "/etc/lib/something.so", Constructors: []string{"ProvideSomething", "NewSomethingElse"}, OnStart: "Initialize", /* other fields filled out as desired */ }.Provide() )
type Set ¶ added in v0.0.1
type Set 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. Paths []string // IgnoreMissingConstructors controls what happens if a symbol in the Constructors // field is not present in any of the plugins. If this field is true, missing constructor // symbols are silently ignored. Otherwise, missing constructor symbols will shortcircuit // application startup with one or more errors. IgnoreMissingConstructors bool // Constructors are the optional exported functions from each plugin that participate // in dependency injection. Each constructor is passed to fx.Provide. Constructors []string // IgnoreMissingLifecycle controls what happens if OnStart or OnStop are not symbols // in each plugin. If this field is true and either OnStart or OnStop are not present, // no error is raised. Otherwise, application startup is shortcircuited with one or // more errors. IgnoreMissingLifecycle bool // OnStart is the optional exported function that should be called when the enclosing // application is started. OnStart string // OnStop is the optional exported function that should be called when the enclosing // application is stopped. OnStop string }
Set describes how to load multiple plugins as a bundle and integrate each of them into an enclosing fx.App.
type SymbolMap ¶
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".
func (*SymbolMap) Set ¶
Set establishes a symbol, overwriting any existing symbol with the given name. This method panics if value is not a function or a non-nil pointer, which are the only allowed types of symbols in an actual plugin.
type SymbolVisitor ¶ added in v0.0.1
SymbolVisitor is a callback for symbols. If an error is returned from Lookup, this callback is passed and invalid value along with that error. Otherwise, this callback is passed the value of the symbol, and lookupErr will be nil.
If this callback itself returns an error, then visitation is halted and that error is returned.