From 880b90003d1307d5748d26b392f39647aee12485 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Mon, 11 Nov 2019 22:52:10 +0900 Subject: [PATCH] bug fixed --- annotation/annotation.go | 8 +++++++- injection/annotation/component.go | 8 ++++---- injection/annotation/inject.go | 3 ++- injection/annotation/resource.go | 2 +- registry/registry.go | 1 + 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/annotation/annotation.go b/annotation/annotation.go index 2cec4c3..298b6ec 100644 --- a/annotation/annotation.go +++ b/annotation/annotation.go @@ -140,7 +140,13 @@ func splitAnnotationAttribute(s string) (map[string]string, error) { aas := strings.Index(ts[as:], AnnotationAttributeStartChar) aae := strings.Index(ts[as+aas+1:], AnnotationAttributeEndChar) - ss[aName] = ts[as+aas+1 : as+aas+aae+1] + if -1 == aas && -1 == aae { + ss[aName] = ts[as+1 : len(ts)] + } else if -1 != aas && -1 != aae { + ss[aName] = ts[as+aas+1 : as+aas+aae+1] + } else { + return nil, fmt.Errorf("not valid string %s", ts) + } asi := strings.Index(ts[as+aae:], AnnotationAttributeSpliter) if -1 == asi { diff --git a/injection/annotation/component.go b/injection/annotation/component.go index 5c2a50f..1dd5ab9 100644 --- a/injection/annotation/component.go +++ b/injection/annotation/component.go @@ -17,8 +17,8 @@ func init() { type ComponentAnnotation struct { cda.TypeAnnotation `@annotation:"@Component"` - Name string `@annotation:"name"` - InitMethod string `@annotation:"initMethod"` // func (receiver interface{}, cr ComponentRegistry) error - DestroyMethod string `@annotation:"destroyMethod"` // func (receiver interface{}, cr ComponentRegistry) error - Scope di.ScopeType `@annotation:"scope"` + Name string `json:"name"` + InitMethod string `json:"initMethod"` // func (receiver interface{}, cr ComponentRegistry) error + DestroyMethod string `json:"destroyMethod"` // func (receiver interface{}, cr ComponentRegistry) error + Scope di.ScopeType `json:"scope"` } diff --git a/injection/annotation/inject.go b/injection/annotation/inject.go index e4b0c9a..d48aee3 100644 --- a/injection/annotation/inject.go +++ b/injection/annotation/inject.go @@ -16,5 +16,6 @@ func init() { type InjectAnnotation struct { cda.TypeAnnotation `@annotation:"@Inject"` - Name string `@annotation:"name"` + + Name string `json:"name"` } diff --git a/injection/annotation/resource.go b/injection/annotation/resource.go index 0d30b7c..061d405 100644 --- a/injection/annotation/resource.go +++ b/injection/annotation/resource.go @@ -14,5 +14,5 @@ func init() { type ResourceAnnotation struct { cda.TypeAnnotation `@annotation:"@Resource"` - Name string `@annotation:"name"` + Name string `:"name"` } diff --git a/registry/registry.go b/registry/registry.go index 9ddf125..4a12695 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -58,6 +58,7 @@ func RegisterType(t reflect.Type) { registry.RegisterType(t) } + func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) { if nil == t { log.Panicf("DI: t[reflect.Type] is nil")