container

package
v0.0.0-...-2b8a88d Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNilFunction = errors.New("got nil, expected a function")

Functions

This section is empty.

Types

type Container

type Container struct {
	Graph *Graph
}

func NewContainer

func NewContainer() *Container

func (Container) CreateType

func (c Container) CreateType(typ reflect.Type, args ...interface{}) (interface{}, error)

CreateType returns a newly created value of the supplied type

func (Container) Execute

func (c Container) Execute(fn interface{}, args ...interface{}) (interface{}, error)

Execute will try and call the function with all of the arguments.

func (*Container) HasType

func (c *Container) HasType(t reflect.Type) bool

func (*Container) Provide

func (c *Container) Provide(fn interface{}) error

Provide adds the return types of the function as vertexes on a graph and attempts to add edges based on the arguments of the function

type Edge

type Edge struct {
	From reflect.Type
	To   reflect.Type
	// contains filtered or unexported fields
}

Edge represents the relationship between two types

func (Edge) Equal

func (e Edge) Equal(edge Edge) bool

type Edges

type Edges []*Edge

func (Edges) Contains

func (e Edges) Contains(t reflect.Type) bool

type Graph

type Graph struct {
	Edges    []Edge
	Vertexes map[reflect.Type]*Vertex
}

func GraphFromFunc

func GraphFromFunc(fn interface{}) (*Graph, error)

GraphFromFunc takes in a function and returns a graph containing the functions dependencies and what types it returns

func MergeGraphs

func MergeGraphs(from, to *Graph) *Graph

func NewGraph

func NewGraph() *Graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(from, to reflect.Type)

AddEdge connects two vertices, in the direction of from -> to

func (Graph) Sort

func (g Graph) Sort() ([]reflect.Type, error)

type In

type In struct{}

In is used to mark a struct where each member should be treated as its own dependency

type Vertex

type Vertex struct {

	// the reflect.Type value that the function will return
	Typ reflect.Type

	// slice of pointers to the graphs edges relating to this vertex
	// each edge represents a dependency of the function, incoming being
	// the arguments required, and outgoing for the values provided from this function
	OutgoingEdges Edges
	IncomingEdges Edges
	// contains filtered or unexported fields
}

Vertex represents a reflect.Type and a function that is used to create it.

Jump to

Keyboard shortcuts

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