bug fixed

This commit is contained in:
병준 박 2019-11-13 22:39:48 +09:00
parent e44b732fea
commit 7fe27b5719

View File

@ -22,7 +22,7 @@ type Definition struct {
// Regist is interface
type Regist interface {
// Register is method
Register(t reflect.Type)
Register(t reflect.Type) error
// Parse is method
Parse(tag reflect.StructTag) (map[reflect.Type]Annotation, error)
}
@ -42,22 +42,22 @@ func newRegistry() Regist {
}
// Register is method
func Register(t reflect.Type) {
registry.Register(t)
func Register(t reflect.Type) error {
return registry.Register(t)
}
// Register is method
func (r *Registry) Register(t reflect.Type) {
func (r *Registry) Register(t reflect.Type) error {
rt, _, _ := luReflect.GetTypeInfo(t)
f := r.getTypeAnnotationField(t)
if nil == f {
panic(fmt.Sprintf("Annotation: This type[%s] is not Annotation. use TypeAnnotation", rt.Name()))
return fmt.Errorf("Annotation: This type[%s] is not Annotation. use TypeAnnotation", rt.Name())
}
name := r.parseAnnotationMeta(f.Tag)
if _, ok := r.definitions[name]; ok {
panic(fmt.Sprintf("Annotation: name[%s] of annotation exist already", name))
return fmt.Errorf("Annotation: name[%s] of annotation exist already", name)
}
def := &Definition{
@ -66,6 +66,7 @@ func (r *Registry) Register(t reflect.Type) {
}
r.definitions[name] = def
return nil
}
// Parse is method