Documentation ¶
Index ¶
- Variables
- type Aliases
- type Declaration
- type Dependency
- type Error
- type External
- type Finder
- type Function
- type Generator
- type Injector
- func (i *Injector) Find(currModule *gomod.Module, dep Dependency) (Declaration, error)
- func (i *Injector) Generate(fn *Function) (string, error)
- func (i *Injector) GenerateFile(fn *Function) (string, error)
- func (i *Injector) Load(fn *Function) (*Node, error)
- func (i *Injector) Wire(fn *Function) (*Provider, error)
- type Node
- type Param
- type Params
- type Provider
- type Struct
- type StructField
- type Type
- type Variable
Constants ¶
This section is empty.
Variables ¶
var ErrNoMatch = errors.New("no match")
Functions ¶
This section is empty.
Types ¶
type Aliases ¶
type Aliases map[Dependency]Dependency
type Declaration ¶
type Declaration interface { ID() string Dependencies() []Dependency Generate(gen Generator, inputs []*Variable) (outputs []*Variable) }
type Dependency ¶
type Error ¶
type Error struct { }
Error type
func (*Error) Dependencies ¶
func (*Error) Dependencies() (deps []Dependency)
func (*Error) ImportPath ¶
type Finder ¶
type Finder interface {
Find(module *gomod.Module, dep Dependency) (Declaration, error)
}
Finder finds a declaration that will instantiate the data type
type Function ¶
type Function struct { // Name of the function to generate Name string // Imports to pass through Imports *imports.Set // Params are the external parameters that are passed in Params []*Param // Results are the dependencies that need to be loaded Results []Dependency // Hoist dependencies that don't depend on externals, turning them into // externals. This is to avoid initializing these inner deps every time. // Useful for per-request dependency injection. Hoist bool // Aliases allow you to map one dependency to another. Useful to supporting // interfaces as inputs that are mapped to a concrete value. Aliases Aliases // Target import path where this function will be generated to Target string }
Function is the top-level load function that we generate to provide all the dependencies
func (*Function) Dependencies ¶
func (fn *Function) Dependencies() []Dependency
type Injector ¶
type Injector struct {
// contains filtered or unexported fields
}
func (*Injector) Find ¶
func (i *Injector) Find(currModule *gomod.Module, dep Dependency) (Declaration, error)
func (*Injector) GenerateFile ¶
GenerateFile generates a provider function into a Go file string
type Node ¶
type Node struct { // Type and import of the dependency we were looking for Import string Type string // Declaration that would instantiate this type. This will be nil if the node // is External Declaration Declaration // Dependencies that the declaration relies on to be able to instantiate Dependencies []*Node // External is true if the type matches an external dependency. External types // are passed in, not instantiated. External bool // Hoisted is true if the dependency has been hoisted up. Hoisted types are // passed in, not instantiated. Hoist bool }
node in the dependency injection graph
func Hoist ¶
Hoist the nodes that don't depend on the external nodes and turn these nodes into external nodes. This allows for dependencies that don't depend on externals to be initialized once, rather than each time the generated function is called.
Start with hoisting true, but if we encounter any external along the way, the hoisting of all children becomes false
type Provider ¶
type Provider struct { Name string // Name of the function Target string // Target import path Imports []*imports.Import // Imports needed Externals []*External // External variables Code string // Body of the generated code Results []*Variable // Return variables // contains filtered or unexported fields }
Provider is the result of generating. Provider can generate functions or files or be used for it's template variables.
type Struct ¶
type Struct struct { Import string Type string Fields []*StructField }
Struct is a dependency that can be defined in memory. Struct is also a declaration that can be referenced and be used to generate initializers.
func (*Struct) Dependencies ¶
func (s *Struct) Dependencies() (deps []Dependency)
func (*Struct) Find ¶
func (s *Struct) Find(finder Finder) (Declaration, error)
Find a declaration that provides this type
func (*Struct) ImportPath ¶
type StructField ¶
type StructField struct { Name string Import string Type string // contains filtered or unexported fields }
func (*StructField) Find ¶
func (s *StructField) Find(finder Finder) (Declaration, error)
func (*StructField) ID ¶
func (s *StructField) ID() string
func (*StructField) ImportPath ¶
func (s *StructField) ImportPath() string
func (*StructField) TypeName ¶
func (s *StructField) TypeName() string
type Type ¶
func (*Type) Find ¶
func (t *Type) Find(finder Finder) (Declaration, error)
Find a declaration that provides this type