di/annotation/definition.go

41 lines
756 B
Go
Raw Normal View History

2018-03-15 13:19:44 +00:00
package annotation
import (
2018-03-15 14:38:47 +00:00
"fmt"
2018-03-15 13:19:44 +00:00
"reflect"
2018-03-15 14:38:47 +00:00
"git.loafle.net/commons_go/logging"
2018-03-15 13:19:44 +00:00
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) {
2018-03-15 14:38:47 +00:00
if _, ok := annotationRegistry[name]; ok {
logging.Logger().Panic(fmt.Sprintf("DI: name[%s] of annotation exist already.", name))
}
2018-03-15 13:19:44 +00:00
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
}