From ae210442610888885a156a3ec0c7f50c52dc1a95 Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 20 Mar 2018 11:43:00 +0900 Subject: [PATCH] ing --- annotation/definition.go | 4 ++-- annotation/meta.go | 4 ++-- glide.yaml | 3 ++- registry/definition.go | 4 ++-- registry/registry.go | 12 ++++++------ util/reflect/type.go | 23 ----------------------- 6 files changed, 14 insertions(+), 36 deletions(-) delete mode 100644 util/reflect/type.go diff --git a/annotation/definition.go b/annotation/definition.go index 5718412..a0e0d6d 100644 --- a/annotation/definition.go +++ b/annotation/definition.go @@ -6,7 +6,7 @@ import ( "git.loafle.net/commons_go/logging" - cdur "git.loafle.net/commons_go/di/util/reflect" + cur "git.loafle.net/commons_go/util/reflect" ) var annotationRegistry map[string]*AnnotationDefinition @@ -21,7 +21,7 @@ func RegisterAnnotation(name string, t reflect.Type) { } meta := getMetaFields(t) - fRT, _, _ := cdur.GetTypeInfo(t) + fRT, _, _ := cur.GetTypeInfo(t) def := &AnnotationDefinition{ t: t, diff --git a/annotation/meta.go b/annotation/meta.go index b249315..470aa48 100644 --- a/annotation/meta.go +++ b/annotation/meta.go @@ -4,7 +4,7 @@ import ( "reflect" "strings" - cdur "git.loafle.net/commons_go/di/util/reflect" + cur "git.loafle.net/commons_go/util/reflect" ) type AnnotationFieldMeta struct { @@ -35,7 +35,7 @@ func (o anotationMetaOptions) Contains(optionName string) bool { func getMetaFields(t reflect.Type) map[string]*AnnotationFieldMeta { fields := make(map[string]*AnnotationFieldMeta, 0) - rt, _, _ := cdur.GetTypeInfo(t) + rt, _, _ := cur.GetTypeInfo(t) if reflect.Struct != rt.Kind() { return fields } diff --git a/glide.yaml b/glide.yaml index ca1272a..8008a32 100644 --- a/glide.yaml +++ b/glide.yaml @@ -1,2 +1,3 @@ package: git.loafle.net/commons_go/di -import: [] +import: +- package: git.loafle.net/commons_go/util diff --git a/registry/definition.go b/registry/definition.go index cf0076d..e190618 100644 --- a/registry/definition.go +++ b/registry/definition.go @@ -5,7 +5,7 @@ import ( "reflect" cda "git.loafle.net/commons_go/di/annotation" - cdur "git.loafle.net/commons_go/di/util/reflect" + cur "git.loafle.net/commons_go/util/reflect" ) type TypeDefinition struct { @@ -48,7 +48,7 @@ func (td *TypeDefinition) GetAnnotationByType(at reflect.Type, includeEmbedding } func checkAnnotation(t reflect.Type, st reflect.Type) bool { - rt, _, _ := cdur.GetTypeInfo(t) + rt, _, _ := cur.GetTypeInfo(t) if reflect.Struct != rt.Kind() { return false } diff --git a/registry/registry.go b/registry/registry.go index 4328806..ac67bd5 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -8,8 +8,8 @@ import ( cda "git.loafle.net/commons_go/di/annotation" cdia "git.loafle.net/commons_go/di/injection/annotation" - cdur "git.loafle.net/commons_go/di/util/reflect" "git.loafle.net/commons_go/logging" + cur "git.loafle.net/commons_go/util/reflect" ) func init() { @@ -58,7 +58,7 @@ func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) { if nil == t { logging.Logger().Panic("DI: t[reflect.Type] is nil") } - if !cdur.IsTypeKind(t, reflect.Struct, true) { + if !cur.IsTypeKind(t, reflect.Struct, true) { logging.Logger().Panic(fmt.Sprintf("DI: t[reflect.Type] must be specified but is %v", t)) } @@ -119,7 +119,7 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) interface{} { var err error - rt, _, _ := cdur.GetTypeInfo(t) + rt, _, _ := cur.GetTypeInfo(t) td, ok := cr.definitionByType[rt] if !ok { td, err = cr.buildDefinition(t) @@ -223,7 +223,7 @@ func (cr *defaultComponentRegistry) buildDefinition(t reflect.Type) (*TypeDefini return nil, fmt.Errorf("t[reflect.Type] is nil") } - rt, pkgName, tName := cdur.GetTypeInfo(t) + rt, pkgName, tName := cur.GetTypeInfo(t) td := &TypeDefinition{} td.FullName = FullName(pkgName, tName) td.PkgName = pkgName @@ -239,7 +239,7 @@ func (cr *defaultComponentRegistry) buildDefinition(t reflect.Type) (*TypeDefini func parseFields(t reflect.Type, td *TypeDefinition) { // fields := make([]*FieldDefinition, 0) - rt, _, _ := cdur.GetTypeInfo(t) + rt, _, _ := cur.GetTypeInfo(t) if reflect.Struct != rt.Kind() { return } @@ -258,7 +258,7 @@ func parseFields(t reflect.Type, td *TypeDefinition) { return } if nil != as && 0 < len(as) { - fRT, fPkgName, fTName := cdur.GetTypeInfo(f.Type) + fRT, fPkgName, fTName := cur.GetTypeInfo(f.Type) fd := &FieldDefinition{ FieldName: f.Name, diff --git a/util/reflect/type.go b/util/reflect/type.go deleted file mode 100644 index f57ee99..0000000 --- a/util/reflect/type.go +++ /dev/null @@ -1,23 +0,0 @@ -package reflect - -import ( - "reflect" -) - -func IsTypeKind(t reflect.Type, kind reflect.Kind, removePtr bool) bool { - if reflect.Ptr == t.Kind() { - if removePtr { - return IsTypeKind(t.Elem(), kind, removePtr) - } - } - - return kind == t.Kind() -} - -func GetTypeInfo(t reflect.Type) (realType reflect.Type, pkgName string, name string) { - if reflect.Ptr == t.Kind() { - return GetTypeInfo(t.Elem()) - } - - return t, t.PkgPath(), t.Name() -}