Documentation ¶
Index ¶
- Constants
- func Members(name string) ([]any, error)
- func Provide(id string) (any, error)
- func RegisterMember(groupId string, object any)
- func RegisterSingleton(id string, object any)
- type DiFile
- type DiFunc
- type DiFuncs
- type DiImport
- type DiPackage
- type Generator
- type Injector
- type Member
- type Parser
- type Provider
Constants ¶
const (
// RegexpText represents the regular expression pattern for parsing annotations.
RegexpText = `^//\s*@(provider|inject|group)\s*\((.*)\s*\)`
)
Variables ¶
This section is empty.
Functions ¶
func Members ¶
Members returns the group of objects associated with the provided group ID. It returns an error if the group does not exist.
func Provide ¶
Provide returns the singleton object associated with the provided ID. It returns an error if the object does not exist.
func RegisterMember ¶
RegisterMember registers a member object with the provided group ID.
func RegisterSingleton ¶
RegisterSingleton registers a singleton object with the provided ID.
Types ¶
type DiFunc ¶
type DiFunc struct { Name string Injectors []*Injector ProviderId string GroupId string Sort int Package *DiPackage File *DiFile }
DiFunc represents a function with valid annotations. DiFunc表示被合法的注解的函数
type DiFuncs ¶
type DiFuncs []*DiFunc
DiFuncs represents an array of functions with valid annotations. DiFuncs 表示被合法的注解的函数数组
func (DiFuncs) Less ¶
Less compares the elements at positions i and j in the slice and returns true if the element at position i is less than the element at position j.
type DiImport ¶
type DiImport struct { Name string // name represents the package name. Path string // Path represents the import path. }
DiImport represents an import statement in Go source code, recording the imported package name and path. DiImport 表示go源代码中的一个improt语句信息,记录引入的包名和别名
type DiPackage ¶
type DiPackage struct { Name string Path string Folder string Funcs DiFuncs Files map[string]*DiFile }
DiPackage represents a package in Go source code. DiPackage 表示一个go源代码的一个包
type Generator ¶
type Generator struct { Package *DiPackage CalledInitFuncs []ast.Stmt // Initialization functions for singleton objects Fset *token.FileSet // FileSet for token positions Decls []ast.Decl // Functions generated by the provider ImportSpecs map[string]ast.Spec // Packages to be imported ManagerPackage string RegisterFunction string ProvideFunction string GroupFunction string GeneratedFileName string }
Generator is a code generator for dependency injection.
func NewGenerator ¶
NewGenerator creates a new Generator with the given path, package name, and filename.
type Injector ¶
type Injector struct { ProviderId string `json:"id"` // Id represents the identifier of the provider. Pkg string Param string // Param represents the parameter name. Alias string Typ ast.Expr // Typ represents the type of the parameter. Dependency *DiFunc }
Injector represents an injector parameter.
func (*Injector) GetArgName ¶
GetArgName returns the variable name of the injector parameter, which is passed to the provider's constructor. GetArgName 返回injector注解的变量名,这个变量用来传递给provider的构造函数
func (*Injector) GetObjName ¶
GetObjName returns the temporary variable name for the injector parameter, which has the "any" type. GetObjName 返回injector注解的参数的临时变量名,这个变量是any类型.
type Member ¶
type Member struct {
GroupId string `json:"id"` // GroupId represents the group ID of the member.
}
Member represents a member in a group.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
group
This file is generated by digogen.
|
This file is generated by digogen. |
multipackage/controllers
This file is generated by digogen.
|
This file is generated by digogen. |
multipackage/database
This file is generated by digogen.
|
This file is generated by digogen. |
multipackage/models
This file is generated by digogen.
|
This file is generated by digogen. |
simple
This file is generated by digogen.
|
This file is generated by digogen. |