Documentation
¶
Overview ¶
Package wire provides compile-time dependency injection logic as a Go library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type IfaceBinding ¶
type IfaceBinding struct {
// Iface is the interface type, which is what can be injected.
Iface types.Type
// Provided is always a type that is assignable to Iface.
Provided types.Type
// Pos is the position where the binding was declared.
Pos token.Pos
}
An IfaceBinding declares that a type should be used to satisfy inputs of the given interface type.
type Info ¶
type Info struct {
Fset *token.FileSet
// Sets contains all the provider sets in the initial packages.
Sets map[ProviderSetID]*ProviderSet
// Injectors contains all the injector functions in the initial packages.
// The order is undefined.
Injectors []*Injector
}
Info holds the result of Load.
type Provider ¶
type Provider struct {
// ImportPath is the package path that the Go object resides in.
ImportPath string
// Name is the name of the Go object.
Name string
// Pos is the source position of the func keyword or type spec
// defining this provider.
Pos token.Pos
// Args is the list of data dependencies this provider has.
Args []ProviderInput
// IsStruct is true if this provider is a named struct type.
// Otherwise it's a function.
IsStruct bool
// Fields lists the field names to populate. This will map 1:1 with
// elements in Args.
Fields []string
// Out is the type this provider produces.
Out types.Type
// HasCleanup reports whether the provider function returns a cleanup
// function. (Always false for structs.)
HasCleanup bool
// HasErr reports whether the provider function can return an error.
// (Always false for structs.)
HasErr bool
}
Provider records the signature of a provider. A provider is a single Go object, either a function or a named struct type.
type ProviderInput ¶
ProviderInput describes an incoming edge in the provider graph.
type ProviderOrValue ¶
type ProviderOrValue struct {
// contains filtered or unexported fields
}
ProviderOrValue is a pointer to a Provider or a Value. The zero value is a nil pointer.
func (ProviderOrValue) IsNil ¶
func (pv ProviderOrValue) IsNil() bool
IsNil reports whether pv is the zero value.
func (ProviderOrValue) IsProvider ¶
func (pv ProviderOrValue) IsProvider() bool
IsProvider reports whether pv points to a Provider.
func (ProviderOrValue) IsValue ¶
func (pv ProviderOrValue) IsValue() bool
IsValue reports whether pv points to a Value.
func (ProviderOrValue) Provider ¶
func (pv ProviderOrValue) Provider() *Provider
Provider returns pv as a Provider pointer. It panics if pv points to a Value.
func (ProviderOrValue) Value ¶
func (pv ProviderOrValue) Value() *Value
Provider returns pv as a Value pointer. It panics if pv points to a Provider.
type ProviderSet ¶
type ProviderSet struct {
// Pos is the position of the call to wire.NewSet or wire.Build that
// created the set.
Pos token.Pos
// PkgPath is the import path of the package that declared this set.
PkgPath string
// VarName is the variable name of the set, if it came from a package
// variable.
VarName string
Providers []*Provider
Bindings []*IfaceBinding
Values []*Value
Imports []*ProviderSet
// contains filtered or unexported fields
}
A ProviderSet describes a set of providers. The zero value is an empty ProviderSet.
func (*ProviderSet) For ¶
func (set *ProviderSet) For(t types.Type) ProviderOrValue
For returns the provider or value for the given type, or the zero ProviderOrValue.
func (*ProviderSet) Outputs ¶
func (set *ProviderSet) Outputs() []types.Type
Outputs returns a new slice containing the set of possible types the provider set can produce. The order is unspecified.
type ProviderSetID ¶
A ProviderSetID identifies a named provider set.
func (ProviderSetID) String ¶
func (id ProviderSetID) String() string
String returns the ID as ""path/to/pkg".Foo".