di/annotation/definition.go
crusader 52e9415760 ing
2018-03-21 18:28:21 +09:00

41 lines
713 B
Go

package annotation
import (
"fmt"
"reflect"
cur "git.loafle.net/commons_go/util/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
}