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 ProvidedType ¶
type ProvidedType struct {
// contains filtered or unexported fields
}
ProvidedType is a pointer to a Provider or a Value. The zero value is a nil pointer. It also holds the concrete type that the Provider or Value provided.
func (ProvidedType) ConcreteType ¶
func (pv ProvidedType) ConcreteType() types.Type
ConcreteType returns the concrete type that was provided.
func (ProvidedType) IsNil ¶
func (pv ProvidedType) IsNil() bool
IsNil reports whether pv is the zero value.
func (ProvidedType) IsProvider ¶
func (pv ProvidedType) IsProvider() bool
IsProvider reports whether pv points to a Provider.
func (ProvidedType) IsValue ¶
func (pv ProvidedType) IsValue() bool
IsValue reports whether pv points to a Value.
func (ProvidedType) Provider ¶
func (pv ProvidedType) Provider() *Provider
Provider returns pv as a Provider pointer. It panics if pv points to a Value.
func (ProvidedType) Value ¶
func (pv ProvidedType) Value() *Value
Value returns pv as a Value pointer. It panics if pv points to a Provider.
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 set of types this provider produces. It will always // contain at least one type. 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 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) ProvidedType
For returns a ProvidedType for the given type, or the zero ProvidedType.
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".