Documentation ¶
Overview ¶
Package factory contains a "factory" pattern based on argmapper.
A Factory can be used to register factory methods to create some predefined type or interface implementation. These functions are argmapper functions so converters and so on can be used as part of instantiation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory keeps track of named dependency-injected factory functions to create an implementation of an interface.
func New ¶
New creates a Factory for the interface iface. The parameter iface should be a nil pointer to the interface type. Example: (*iface)(nil).
func (*Factory) Copy ¶
Copy returns a copy of Factory. Any registrations on the copy will not reflect the original and vice versa.
func (*Factory) Func ¶
Func returns the factory function named name. This can then be used to call and instantiate the factory interface type.
func (*Factory) Register ¶
Register registers a factory function named name for the interface.
This will error if the function given doesn't result in a single non-error output that implements the interface registered with this factory. The function return signature can be: (T) or (T, error) where T implements the interface type for this factory.
T is allowed to be a literal interface{} type. In this case, it is the callers responsibility to ensure the result is the proper type.
fn may take any number and types of inputs. It is the callers responsibilty when using Func and Call to pass in the required parameters.
func (*Factory) Registered ¶
Registered returns the names registered with this factory.