package annotation import ( "fmt" "reflect" cur "git.loafle.net/commons/util-go/reflect" ) var annotationRegistry map[string]*AnnotationDefinition func init() { annotationRegistry = make(map[string]*AnnotationDefinition, 0) } func RegisterAnnotation(name string, t reflect.Type) error { if _, ok := annotationRegistry[name]; ok { return fmt.Errorf("DI: name[%s] of annotation exist already", name) } meta := getMetaFields(t) fRT, _, _ := cur.GetTypeInfo(t) def := &AnnotationDefinition{ t: t, rt: fRT, fields: meta, } annotationRegistry[name] = def return nil } type AnnotationDefinition struct { t reflect.Type rt reflect.Type fields map[string]*AnnotationFieldMeta }