refer

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildReferencesDecorator

type BuildReferencesDecorator struct {
	*ReferencesDecorator
}

BuildReferencesDecorator references decorator that automatically creates missing components using available component factories upon component retrival.

func NewBuildReferencesDecorator

func NewBuildReferencesDecorator(nextReferences crefer.IReferences,
	topReferences crefer.IReferences) *BuildReferencesDecorator

NewBuildReferencesDecorator creates a new instance of the decorator.

Parameters:
	- nextReferences crefer.IReferences the next references or decorator in the chain.
	- topReferences IReferences the decorator at the top of the chain.
Returns: *BuildReferencesDecorator

func (*BuildReferencesDecorator) ClarifyLocator

func (c *BuildReferencesDecorator) ClarifyLocator(locator any,
	factory build.IFactory) any

ClarifyLocator a component locator by merging two descriptors into one to replace missing fields. That allows to get a more complete descriptor that includes all possible fields.

Parameters:
	- locator any a component locator to clarify.
	- factory build.IFactory a factory that shall create the component.
Returns: any clarified component descriptor (locator)

func (*BuildReferencesDecorator) Create

func (c *BuildReferencesDecorator) Create(locator any,
	factory build.IFactory) any

Create creates a component identified by given locator.

throws a CreateEerror if the factory is not able to create the component.
see FindFactory
Parameters:
	- locator any a locator to identify component to be created.
	- factory build.IFactory a factory that shall create the component.
Returns: any the created component.

func (*BuildReferencesDecorator) Find

func (c *BuildReferencesDecorator) Find(locator any, required bool) ([]any, error)

Find all component references that match specified locator.

throws a ReferenceError when required is set to true but no references found.
Parameters:
	- locator interface the locator to find a reference by.
	- required bool forces to raise an exception if no reference is found.
Returns: []interface, error a list with matching component references and error.

func (*BuildReferencesDecorator) FindFactory

func (c *BuildReferencesDecorator) FindFactory(locator any) build.IFactory

FindFactory finds a factory capable creating component by given descriptor from the components registered in the references.

Parameters:
	- locator any a locator of component to be created.
Returns: build.IFactory found factory or nil if factory was not found.

func (*BuildReferencesDecorator) GetOneOptional

func (c *BuildReferencesDecorator) GetOneOptional(locator any) any

GetOneOptional gets an optional component reference that matches specified locator.

Parameters:
	- locator any the locator to find references by.
Returns: any a matching component reference or nil if nothing was found.

func (*BuildReferencesDecorator) GetOneRequired

func (c *BuildReferencesDecorator) GetOneRequired(locator any) (any, error)

GetOneRequired a required component reference that matches specified locator.

throws a ReferenceException when no references found.
Parameters:
	- locator any the locator to find a reference by.
Returns: any, error a matching component reference and error.

func (*BuildReferencesDecorator) GetOptional

func (c *BuildReferencesDecorator) GetOptional(locator any) []any

GetOptional all component references that match specified locator.

Parameters:
	- locator any the locator to find references by.
Returns: []any a list with matching component references or empty list if nothing was found.

func (*BuildReferencesDecorator) GetRequired

func (c *BuildReferencesDecorator) GetRequired(locator any) ([]any, error)

GetRequired all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error.

throws a ReferenceException when no references found.
Parameters:
	- locator any the locator to find references by.
Returns: []any, erorr a list with matching component references and error.

type ContainerReferences

type ContainerReferences struct {
	*ManagedReferences
}

ContainerReferences container managed references that can be created from container configuration.

func NewContainerReferences

func NewContainerReferences() *ContainerReferences

NewContainerReferences creates a new instance of the references Returns *ContainerReferences

func (*ContainerReferences) PutFromConfig

func (c *ContainerReferences) PutFromConfig(ctx context.Context, config config.ContainerConfig) error

PutFromConfig puts components into the references from container configuration.

Parameters:
	- ctx context.Context
	- config config.ContainerConfig a container
		configuration with information of components to be added.
Returns: error CreateError when one of component cannot be created.

type LinkReferencesDecorator

type LinkReferencesDecorator struct {
	*ReferencesDecorator
	// contains filtered or unexported fields
}

LinkReferencesDecorator references decorator that automatically sets references to newly added components that implement IReferenceable interface and unsets references from removed components that implement IUnreferenceable interface.

func NewLinkReferencesDecorator

func NewLinkReferencesDecorator(nextReferences crefer.IReferences,
	topReferences crefer.IReferences) *LinkReferencesDecorator

NewLinkReferencesDecorator creates a new instance of the decorator.

Parameters:
	- nextReferences crefer.IReferences the next references or decorator in the chain.
	- topReferences crefer.IReferences the decorator at the top of the chain.
Returns: *LinkReferencesDecorator

func (*LinkReferencesDecorator) Close

func (c *LinkReferencesDecorator) Close(ctx context.Context, correlationId string) error

Close closes component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

func (*LinkReferencesDecorator) IsOpen

func (c *LinkReferencesDecorator) IsOpen() bool

IsOpen checks if the component is opened.

Returns: bool true if the component has been opened and false otherwise.

func (*LinkReferencesDecorator) Open

func (c *LinkReferencesDecorator) Open(ctx context.Context, correlationId string) error

Open the component.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

func (*LinkReferencesDecorator) Put

func (c *LinkReferencesDecorator) Put(ctx context.Context, locator any, component any)

Put a new reference into this reference map.

Parameters:
	- ctx context.Context
	- locator any a locator to find the reference by.
	- component any a component reference to be added.

func (*LinkReferencesDecorator) Remove

func (c *LinkReferencesDecorator) Remove(ctx context.Context, locator any) any

Remove a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll method instead.

see RemoveAll
Parameters:
	- ctx context.Context
	- locator interface a locator to remove reference
Returns: any the removed component reference.

func (*LinkReferencesDecorator) RemoveAll

func (c *LinkReferencesDecorator) RemoveAll(ctx context.Context, locator any) []any

RemoveAll removes all component references that match the specified locator.

Parameters:
	- ctx context.Context
	- locator interface a locator to remove reference
Returns: []any a list, containing all removed references.

type ManagedReferences

type ManagedReferences struct {
	*ReferencesDecorator
	References *crefer.References
	Builder    *BuildReferencesDecorator
	Linker     *LinkReferencesDecorator
	Runner     *RunReferencesDecorator
}

ManagedReferences managed references that in addition to keeping and locating references can also manage their lifecycle:

Auto-creation of missing component using available factories
Auto-linking newly added components
Auto-opening newly added components
Auto-closing removed components

func NewEmptyManagedReferences

func NewEmptyManagedReferences() *ManagedReferences

NewEmptyManagedReferences creates a new instance of the references

Returns: *ManagedReferences

func NewManagedReferences

func NewManagedReferences(ctx context.Context, tuples []any) *ManagedReferences

NewManagedReferences creates a new instance of the references

Parameters:
	- ctx context.Context
	- tuples []any tuples where odd values are component locators
		(descriptors) and even values are component references
Returns: *ManagedReferences

func NewManagedReferencesFromTuples

func NewManagedReferencesFromTuples(ctx context.Context, tuples ...any) *ManagedReferences

NewManagedReferencesFromTuples creates a new ManagedReferences object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of locator1, component1, locator2, component2, ... pairs.

Parameters:
	- ctx context.Context
	- tuples ...any the tuples to fill a new ManagedReferences object.
Returns: *ManagedReferences a new ManagedReferences object.

func (*ManagedReferences) Close

func (c *ManagedReferences) Close(ctx context.Context, correlationId string) error

Close component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

func (*ManagedReferences) IsOpen

func (c *ManagedReferences) IsOpen() bool

IsOpen checks if the component is opened.

Returns: bool true if the component has been opened and false otherwise.

func (*ManagedReferences) Open

func (c *ManagedReferences) Open(ctx context.Context, correlationId string) error

Open the component.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

type ReferencesDecorator

type ReferencesDecorator struct {
	NextReferences crefer.IReferences
	TopReferences  crefer.IReferences
}

ReferencesDecorator chainable decorator for IReferences that allows to inject additional capabilities such as automatic component creation, automatic registration and opening.

func NewReferencesDecorator

func NewReferencesDecorator(nextReferences crefer.IReferences,
	topReferences crefer.IReferences) *ReferencesDecorator

NewReferencesDecorator creates a new instance of the decorator.

Parameters:
	- nextReferences crefer.IReferences the next references or decorator in the chain.
	- topReferences crefer.IReferences the decorator at the top of the chain.
Returns: *ReferencesDecorator

func (*ReferencesDecorator) Find

func (c *ReferencesDecorator) Find(locator any, required bool) ([]any, error)

Find all component references that match specified locator.

Parameters:
	- locator any the locator to find a reference by.
	- required bool forces to raise an exception if no reference is found.
Returns: []any, error a list with matching component references and
	a ReferenceError when required is set to true but no references found

func (*ReferencesDecorator) GetAll

func (c *ReferencesDecorator) GetAll() []any

GetAll all component references registered in this reference map.

Returns: []any a list with component references.

func (*ReferencesDecorator) GetAllLocators

func (c *ReferencesDecorator) GetAllLocators() []any

GetAllLocators locators for all registered component references in this reference map.

Returns: []any a list with component locators.

func (*ReferencesDecorator) GetOneOptional

func (c *ReferencesDecorator) GetOneOptional(locator any) any

GetOneOptional gets an optional component reference that matches specified locator.

Parameters:
	- locator any a locator to remove reference
Returns: any a matching component reference or null if nothing was found.

func (*ReferencesDecorator) GetOneRequired

func (c *ReferencesDecorator) GetOneRequired(locator any) (any, error)

GetOneRequired a required component reference that matches specified locator.

Parameters:
	- locator any a locator to remove reference
Returns: any, error a matching component reference, a ReferenceError when no references found.

func (*ReferencesDecorator) GetOptional

func (c *ReferencesDecorator) GetOptional(locator any) []any

GetOptional all component references that match specified locator.

Parameters:
	- locator any a locator to remove reference
Returns: []any a list with matching component references or empty list if nothing was found.

func (*ReferencesDecorator) GetRequired

func (c *ReferencesDecorator) GetRequired(locator any) ([]any, error)

GetRequired all component references that match specified locator. At least one component reference must be present. If it doesn't the method throws an error.

Parameters:
	- locator any a locator to remove reference
Returns []any a list with matching component references and
	error a ReferenceError when no references found.

func (*ReferencesDecorator) Put

func (c *ReferencesDecorator) Put(ctx context.Context, locator any, component any)

Put a new reference into this reference map.

Parameters:
	- ctx context.Context
	- locator any a locator to find the reference by.
	- component any a component reference to be added.

func (*ReferencesDecorator) Remove

func (c *ReferencesDecorator) Remove(ctx context.Context, locator any) any

Remove a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll method instead. see RemoveAll

Parameters:
	- ctx context.Context
	- locator any a locator to remove reference
Returns: any the removed component reference.

func (*ReferencesDecorator) RemoveAll

func (c *ReferencesDecorator) RemoveAll(ctx context.Context, locator any) []any

RemoveAll all component references that match the specified locator.

Parameters:
	- ctx context.Context
	- locator any a locator to remove reference
Returns: []any a list, containing all removed references.

type RunReferencesDecorator

type RunReferencesDecorator struct {
	*ReferencesDecorator
	// contains filtered or unexported fields
}

RunReferencesDecorator References decorator that automatically opens to newly added components that implement IOpenable interface and closes removed components that implement ICloseable interface.

func NewRunReferencesDecorator

func NewRunReferencesDecorator(nextReferences crefer.IReferences,
	topReferences crefer.IReferences) *RunReferencesDecorator

NewRunReferencesDecorator creates a new instance of the decorator.

Parameters:
	- nextReferences crefer.IReferences the next references or decorator in the chain.
	- topReferences crefer.IReferences the decorator at the top of the chain.
Returns: *RunReferencesDecorator

func (*RunReferencesDecorator) Close

func (c *RunReferencesDecorator) Close(ctx context.Context, correlationId string) error

Close component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

func (*RunReferencesDecorator) IsOpen

func (c *RunReferencesDecorator) IsOpen() bool

IsOpen checks if the component is opened.

Returns: bool true if the component has been opened and false otherwise.

func (*RunReferencesDecorator) Open

func (c *RunReferencesDecorator) Open(ctx context.Context, correlationId string) error

Open the component.

Parameters:
	- ctx context.Context
	- correlationId string transaction id to trace execution through call chain.
Returns: error

func (*RunReferencesDecorator) Put

func (c *RunReferencesDecorator) Put(ctx context.Context, locator any, component any)

Put a new reference into this reference map.

Parameters:
	- ctx context.Context
	- locator any a locator to find the reference by.
	- component any a component reference to be added.

func (*RunReferencesDecorator) Remove

func (c *RunReferencesDecorator) Remove(ctx context.Context, locator any) any

Remove a previously added reference that matches specified locator. If many references match the locator, it removes only the first one. When all references shall be removed, use removeAll method instead.

see RemoveAll
Parameters:
	- ctx context.Context
	- locator any the locator to remove references by.
Returns: any the removed component reference.

func (*RunReferencesDecorator) RemoveAll

func (c *RunReferencesDecorator) RemoveAll(ctx context.Context, locator any) []any

RemoveAll all component references that match the specified locator.

Parameters:
	- ctx context.Context
	- locator any the locator to remove references by.
Returns: []any a list, containing all removed references.

Jump to

Keyboard shortcuts

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