refactoring

This commit is contained in:
병준 박 2019-11-13 22:53:42 +09:00
parent 0d94b71049
commit a3974dc218
3 changed files with 11 additions and 13 deletions

View File

@ -6,7 +6,6 @@ import (
"reflect"
"strings"
"git.loafle.net/loafer/annotation-go/annotations"
luReflect "git.loafle.net/loafer/util-go/reflect"
)
@ -25,7 +24,7 @@ type Regist interface {
// Register is method
Register(t reflect.Type) error
// Parse is method
Parse(tag reflect.StructTag) (map[reflect.Type]annotations.Annotation, error)
Parse(tag reflect.StructTag) (map[reflect.Type]Annotation, error)
}
// Registry is struct
@ -71,12 +70,12 @@ func (r *Registry) Register(t reflect.Type) error {
}
// Parse is method
func Parse(tag reflect.StructTag) (map[reflect.Type]annotations.Annotation, error) {
func Parse(tag reflect.StructTag) (map[reflect.Type]Annotation, error) {
return registry.Parse(tag)
}
// Parse is method
func (r *Registry) Parse(tag reflect.StructTag) (map[reflect.Type]annotations.Annotation, error) {
func (r *Registry) Parse(tag reflect.StructTag) (map[reflect.Type]Annotation, error) {
s := strings.Trim(tag.Get(AnnotationTag), " ")
if "" == s {
return nil, nil
@ -91,7 +90,7 @@ func (r *Registry) Parse(tag reflect.StructTag) (map[reflect.Type]annotations.An
return nil, nil
}
rKVs := make(map[reflect.Type]annotations.Annotation, 0)
rKVs := make(map[reflect.Type]Annotation, 0)
for name, attributes := range am {
t, annotation, err := r.buildAnnotation(name, attributes)
if nil != err {
@ -113,7 +112,7 @@ func (r *Registry) getTypeAnnotationField(t reflect.Type) *reflect.StructField {
f := rt.Field(i)
if f.Anonymous {
if f.Type == annotations.TypeAnnotationType {
if f.Type == TypeAnnotationType {
return &f
}
}
@ -154,14 +153,14 @@ func (r *Registry) splitAnnotation(s string) (map[string]string, error) {
return ss, nil
}
func (r *Registry) buildAnnotation(name string, attributes string) (reflect.Type, annotations.Annotation, error) {
func (r *Registry) buildAnnotation(name string, attributes string) (reflect.Type, Annotation, error) {
def, ok := r.definitions[name]
if !ok {
return nil, nil, fmt.Errorf("There is no annotation[%s]", name)
}
v := reflect.New(def.rt)
i := v.Interface().(annotations.Annotation)
i := v.Interface().(Annotation)
if "" != attributes {
_json := fmt.Sprintf("{%s}", attributes)

View File

@ -1,7 +1,6 @@
package annotation
import (
"git.loafle.net/loafer/annotation-go/annotations"
"reflect"
"testing"
)
@ -70,7 +69,7 @@ func TestParse(t *testing.T) {
tests := []struct {
name string
args args
want map[reflect.Type]annotations.Annotation
want map[reflect.Type]Annotation
wantErr bool
}{
// TODO: Add test cases.
@ -100,7 +99,7 @@ func TestRegistry_Parse(t *testing.T) {
name string
fields fields
args args
want map[reflect.Type]annotations.Annotation
want map[reflect.Type]Annotation
wantErr bool
}{
// TODO: Add test cases.
@ -222,7 +221,7 @@ func TestRegistry_buildAnnotation(t *testing.T) {
fields fields
args args
want reflect.Type
want1 annotations.Annotation
want1 Annotation
wantErr bool
}{
// TODO: Add test cases.

View File

@ -1,4 +1,4 @@
package annotations
package annotation
import "reflect"