depend

package
v0.0.0-...-950a071 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2017 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package depend provides the core data types for the buildtime dependency injection system.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRoot is the error used to indicate a root has not been
	// set on a Container for an operation that requires such a root.
	ErrNoRoot = errors.New("no root set for container")

	// ErrRootAlreadySet is the error used to indicate that a root has
	// already been set on a Container for an operation that only allows
	// the root to be set once.
	ErrRootAlreadySet = errors.New("root already set for container")

	// ErrAmbiguousRootDetected is the error used to indicate that an attempt
	// to auto-detect the root has found more than one root candidate.
	ErrAmbiguousRootDetected = errors.New("root auto-detection found ambiguous root candidates")
)

Functions

This section is empty.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

A Container exposes the dependencies implicit in set of constructors or static factories as a directed graph.Container implements the graph.Directed interface from github.com/gonum/graph.

func (*Container) AddFunc

func (c *Container) AddFunc(function *types.Func) error

AddFunc adds function to the Container. function should be a constructor or other static factory. The non-error return types of function are made available as components that can satisfy the components required by other functions added to the container. The parameters to the function are required to be satisfied by components in the Container for the Container to be complete. function can have an error return type as its last return type.

AddFunc will auto-detect root types that are provided by function. A root type for this purpose is a types.Type whose method set includes a nullary method named "Run". AddFunc will return an error if it auto-detects a second root type for the Container.

AddFunc will return an InvalidFuncError for a function with an error return type in any position except the last. It will also return an InvalidFuncError if a method is passed in as function.

func (*Container) Edge

func (c *Container) Edge(u graph.Node, v graph.Node) graph.Edge

Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.

func (*Container) From

func (c *Container) From(node graph.Node) []graph.Node

From returns all nodes that can be reached directly from the given node.

func (*Container) Has

func (c *Container) Has(node graph.Node) bool

Has returns whether a node exists within the Container.

func (*Container) HasEdgeBetween

func (c *Container) HasEdgeBetween(x graph.Node, y graph.Node) bool

HasEdgeBetween returns whether an edge exists between nodes x and y without considering the direction.

func (*Container) HasEdgeFromTo

func (c *Container) HasEdgeFromTo(u graph.Node, v graph.Node) bool

HasEdgeFromTo returns whether an edge exists in the Container from u to v.

func (*Container) Nodes

func (c *Container) Nodes() []graph.Node

Nodes returns all of the nodes within the Container.

func (*Container) Root

func (c *Container) Root() (graph.Node, error)

Root returns the root node of the container or ErrNoRoot is a root has not been set.

func (*Container) To

func (c *Container) To(node graph.Node) []graph.Node

To returns all nodes that can reach directly to the given node.

type Error

type Error interface {
	error

	// Pos returns the position associated with this error.
	Pos() token.Pos

	// ErrorWithPosition returns the error message for the error preceded with
	// the string representation of the position as given by the token.FileSet.
	ErrorWithPosition(fileSet *token.FileSet) string
}

An Error represents an error with an associated position in an implicit token.FileSet.

type InvalidFuncError

type InvalidFuncError struct {
	// contains filtered or unexported fields
}

InvalidFuncError records an error with an attempt to add an invalid types.Func to a Container. InvalidFuncError implements Error.

func (*InvalidFuncError) Error

func (ife *InvalidFuncError) Error() string

func (*InvalidFuncError) ErrorWithPosition

func (ife *InvalidFuncError) ErrorWithPosition(fileSet *token.FileSet) string

func (*InvalidFuncError) Pos

func (ife *InvalidFuncError) Pos() token.Pos

Jump to

Keyboard shortcuts

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