di/annotation/definition.go
crusader 64af0e5f73 ing
2018-03-15 23:38:47 +09:00

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
}