ing
This commit is contained in:
parent
c3e8cd5718
commit
1ab0bb37bf
|
@ -1,21 +0,0 @@
|
|||
package annotations
|
||||
|
||||
// @Inject(name? string)
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.loafle.net/loafer/annotation-go"
|
||||
)
|
||||
|
||||
var InjectAnnotationType = reflect.TypeOf((*InjectAnnotation)(nil))
|
||||
|
||||
func init() {
|
||||
annotation.Register(InjectAnnotationType)
|
||||
}
|
||||
|
||||
type InjectAnnotation struct {
|
||||
annotation.TypeAnnotation `@annotation:"@Inject"`
|
||||
|
||||
Name string `json:"name"`
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package annotations
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"git.loafle.net/loafer/annotation-go"
|
||||
)
|
||||
|
||||
var ResourceAnnotationType = reflect.TypeOf((*ResourceAnnotation)(nil))
|
||||
|
||||
func init() {
|
||||
annotation.Register(ResourceAnnotationType)
|
||||
}
|
||||
|
||||
type ResourceAnnotation struct {
|
||||
annotation.TypeAnnotation `@annotation:"@Resource"`
|
||||
Name string `json:"name"`
|
||||
}
|
2
go.mod
2
go.mod
|
@ -3,6 +3,6 @@ module git.loafle.net/loafer/di-go
|
|||
go 1.13
|
||||
|
||||
require (
|
||||
git.loafle.net/loafer/annotation-go v0.0.0-20191112145817-e44b732fea76
|
||||
git.loafle.net/loafer/annotation-go v0.0.0-20191113135342-a3974dc21898
|
||||
git.loafle.net/loafer/util-go v0.0.0-20191113132317-6eeae49d258d
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
|||
git.loafle.net/loafer/annotation-go v0.0.0-20191112145817-e44b732fea76 h1:fUggcxR3GQLUeDVt2vuLJ7NW20sdr+Cnk/Q0uOioBLI=
|
||||
git.loafle.net/loafer/annotation-go v0.0.0-20191112145817-e44b732fea76/go.mod h1:1yow6wwbB3nWq6Asgt3BAPfXJTjZeqgMYF+VVPlj9Xk=
|
||||
git.loafle.net/loafer/annotation-go v0.0.0-20191113135342-a3974dc21898 h1:3moCEHhGfzHTQVBde+IkvB42oDGUdpCDkBWjN5ZnoL8=
|
||||
git.loafle.net/loafer/annotation-go v0.0.0-20191113135342-a3974dc21898/go.mod h1:1yow6wwbB3nWq6Asgt3BAPfXJTjZeqgMYF+VVPlj9Xk=
|
||||
git.loafle.net/loafer/util-go v0.0.0-20191112142134-9a567d18b779/go.mod h1:HGVw9FNJIc/UFDIzxmoIj5K2+D9Eadal5jjHOq0NFOU=
|
||||
git.loafle.net/loafer/util-go v0.0.0-20191113132317-6eeae49d258d h1:ESDbDHHzH2Ysq+thQrO/OQtyDkVhzNzshjn0SJIqa0g=
|
||||
git.loafle.net/loafer/util-go v0.0.0-20191113132317-6eeae49d258d/go.mod h1:HGVw9FNJIc/UFDIzxmoIj5K2+D9Eadal5jjHOq0NFOU=
|
||||
|
|
11
registry.go
11
registry.go
|
@ -8,7 +8,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"git.loafle.net/loafer/annotation-go"
|
||||
"git.loafle.net/loafer/di-go/annotations"
|
||||
luReflect "git.loafle.net/loafer/util-go/reflect"
|
||||
)
|
||||
|
||||
|
@ -82,8 +81,8 @@ func (r *Registry) RegisterType(t reflect.Type) {
|
|||
|
||||
name := td.TypeName
|
||||
|
||||
if a := td.GetTypeAnnotationByType(annotations.ComponentAnnotationType, true); nil != a {
|
||||
ca := a.(*annotations.ComponentAnnotation)
|
||||
if a := td.GetTypeAnnotationByType(ComponentAnnotationType, true); nil != a {
|
||||
ca := a.(*ComponentAnnotation)
|
||||
if "" != strings.Trim(ca.Name, " ") {
|
||||
name = ca.Name
|
||||
}
|
||||
|
@ -172,14 +171,14 @@ func (r *Registry) GetInstance(t reflect.Type) (instance interface{}, err error)
|
|||
return
|
||||
}
|
||||
|
||||
if annotation = fd.GetAnnotationByType(annotations.InjectAnnotationType, false); nil != annotation {
|
||||
if annotation = fd.GetAnnotationByType(InjectAnnotationType, false); nil != annotation {
|
||||
if fV, err = r.GetInstance(fd.Type); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if annotation = fd.GetAnnotationByType(annotations.ResourceAnnotationType, false); nil != annotation {
|
||||
n := annotation.(*annotations.ResourceAnnotation).Name
|
||||
if annotation = fd.GetAnnotationByType(ResourceAnnotationType, false); nil != annotation {
|
||||
n := annotation.(*ResourceAnnotation).Name
|
||||
if "" == n {
|
||||
n = fd.FieldName
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package annotations
|
||||
package di
|
||||
|
||||
// @Inject(name? string)
|
||||
|
||||
|
@ -8,15 +8,32 @@ import (
|
|||
"git.loafle.net/loafer/annotation-go"
|
||||
)
|
||||
|
||||
var ComponentAnnotationType = reflect.TypeOf((*ComponentAnnotation)(nil))
|
||||
|
||||
func init() {
|
||||
annotation.Register(ComponentAnnotationType)
|
||||
annotation.Register(InjectAnnotationType)
|
||||
annotation.Register(ResourceAnnotationType)
|
||||
}
|
||||
|
||||
var ComponentAnnotationType = reflect.TypeOf((*ComponentAnnotation)(nil))
|
||||
|
||||
type ComponentAnnotation struct {
|
||||
annotation.TypeAnnotation `@annotation:"@Component"`
|
||||
Name string `json:"name"`
|
||||
InitMethod string `json:"initMethod"` // func (receiver interface{}, cr ComponentRegistry) error
|
||||
DestroyMethod string `json:"destroyMethod"` // func (receiver interface{}, cr ComponentRegistry) error
|
||||
}
|
||||
|
||||
var InjectAnnotationType = reflect.TypeOf((*InjectAnnotation)(nil))
|
||||
|
||||
type InjectAnnotation struct {
|
||||
annotation.TypeAnnotation `@annotation:"@Inject"`
|
||||
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
var ResourceAnnotationType = reflect.TypeOf((*ResourceAnnotation)(nil))
|
||||
|
||||
type ResourceAnnotation struct {
|
||||
annotation.TypeAnnotation `@annotation:"@Resource"`
|
||||
Name string `json:"name"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user