41 lines
756 B
Go
41 lines
756 B
Go
package annotation
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
|
|
"git.loafle.net/commons_go/logging"
|
|
|
|
cdur "git.loafle.net/commons_go/di/util/reflect"
|
|
)
|
|
|
|
var annotationRegistry map[string]*AnnotationDefinition
|
|
|
|
func init() {
|
|
annotationRegistry = make(map[string]*AnnotationDefinition, 0)
|
|
}
|
|
|
|
func RegisterAnnotation(name string, t reflect.Type) {
|
|
if _, ok := annotationRegistry[name]; ok {
|
|
logging.Logger().Panic(fmt.Sprintf("DI: name[%s] of annotation exist already.", name))
|
|
}
|
|
|
|
meta := getMetaFields(t)
|
|
fRT, _, _ := cdur.GetTypeInfo(t)
|
|
|
|
def := &AnnotationDefinition{
|
|
t: t,
|
|
rt: fRT,
|
|
fields: meta,
|
|
}
|
|
|
|
annotationRegistry[name] = def
|
|
}
|
|
|
|
type AnnotationDefinition struct {
|
|
t reflect.Type
|
|
rt reflect.Type
|
|
|
|
fields map[string]*AnnotationFieldMeta
|
|
}
|